Repository navigation
fix: harden mailbox cancellation and reply lifecycle - #300
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cancelled receives previously retained a stale callback that could discard the next message, and replies containing
Nonenever 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 bystart(). 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, andgit diff --check.