Skip to content

DeferredCallback: one lifetime owner, not two - #57

Merged
trissim merged 1 commit into
mainfrom
claude-a/qobject-one-lifetime-owner
Nov 17, 2026
Merged

trissim merged 1 commit into
mainfrom
claude-a/qobject-one-lifetime-owner

Conversation

@trissim

@trissim trissim commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The DeferredCallback QTimer no longer self-queues deleteLater() from inside its own slot. The owner QObject's destruction cascade is the one lifetime owner; setSingleShot(True) already stops the timer after one delivery.
  • Regression test test_parentless_owner_drop_mid_eventloop_does_not_segfault rebuilds the specimen from bus message 2f8b474c7a7c: a DeferredCallback whose owner is a local QComboBox dropped between two processEvents() calls.
  • Updated test_deferred_callback_runs_once_and_retires (renamed _and_owner_owns_it) to assert the owner-owned semantics: timer stays as a child of the owner after firing, dies with the owner.

Why

Bus 2f8b474c7a7c showed the full suite SIGSEGV'ing at ~66% in
tests/test_widget_tree_projection.py::test_nominal_widget_projectors_own_indexed_selection:

QObject::event(DeferredDelete) -> PySide QTimer wrapper dtor -> QTimer::~QTimer -> QTimer::stop -> QPropertyBindingData (freed)

self.deleteLater() inside _invoke posted a DeferredDelete that raced the owner's own child-cascade delete. Qt's removePostedEvents protects plain QTimer children, but the PySide wrapper for a Python-subclass QTimer still ran QTimer::~QTimer against freed property-binding storage. The second owner was the slot itself. slop.md IDEN-5: one lifetime owner, not two.

Test plan

  • Targeted suite: tests/test_deferred_callback.py 13 passed on the runtime python (3.14.8, PySide6 6.12.0, offscreen).
  • A/B against HEAD before the fix on the first 11 test files in the suite: both pre-fix and post-fix dump core at a separate test_declared_form.py:86 crash during QTest.qWait(300) — pre-existing QWidget lifetime bug, not a regression of this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_016gZLdupVQyBzHTmHBC9Cyn

The owner is the one owner. DeferredCallback.setSingleShot(True) stops the
timer after one delivery; the owner's destruction cascade cleans it up. The
old self.deleteLater() inside _invoke posted a DeferredDelete that raced the
owner's own child-cascade delete, and under PySide the wrapper still ran
QTimer::~QTimer -> QTimer::stop against freed property-binding storage. The
full suite segfaulted at 66% in
tests/test_widget_tree_projection.py::test_nominal_widget_projectors_own_indexed_selection
(bus 2f8b474c7a7c). IDEN-5 at src/pyqt_reactive/core/deferred_callback.py:32.

A regression test rebuilds the specimen: a DeferredCallback whose parent is
a local QComboBox dropped mid-event-loop.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016gZLdupVQyBzHTmHBC9Cyn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant