Skip to content

fix: harden mailbox cancellation and reply lifecycle - #300

Merged
dbrattli merged 1 commit into
mainfrom
fix/mailbox-lifecycle
Nov 11, 2026
Merged

dbrattli merged 1 commit into
mainfrom
fix/mailbox-lifecycle

Conversation

@dbrattli

Copy link
Copy Markdown
Owner

Cancelled receives previously retained a stale callback that could discard the next message, and replies containing None never completed. Receive ownership now uses a single optional future, with reader exclusion, cancellation registration, timeout, and cleanup scoped by an async context manager. Replies complete on the owning event loop; the first reply wins and late replies are ignored.

Add optional receive/reply timeouts in seconds and wait() to observe body completion, failure, or cancellation. Preserve the message type inferred by start(). Shared task startup now releases completed, failed, and cancelled tasks and their cancellation registrations; CancellationToken.none() supports no-op registration and idle receivers wake on token cancellation. Regression coverage includes cancellation races, duplicate and cross-thread replies, task cleanup, and invalid message types.

Compatibility: construct mailboxes inside a running asyncio event loop and perform receive, request/reply, and wait operations on that loop. Posting and replying remain usable from other threads. Cancelling a reply wait does not retract its message; body termination does not close the queue or settle outstanding replies. The mailbox reference documents these contracts and includes an API example.

Verification commands: python -m pytest -q, ruff check ., ruff format --check ., python scripts/check_typing.py, .pre-commit-hooks/prevent-readme-edits.sh, and git diff --check.

@dbrattli
dbrattli merged commit 64be6f8 into main Nov 11, 2026
6 checks passed
@dbrattli
dbrattli deleted the fix/mailbox-lifecycle branch November 11, 2026 23:48
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