Repository navigation
Stop losing channel messages on None payloads and cancelled receivers - #91
Merged
Merged
Conversation
On a plain asyncio loop, async_receive() still began with try_receive(), which takes a queued None and reports the channel as empty, so the message was lost. It now begins with receive(0) on every loop, which raises TimeoutError only when the channel is empty. When data is already queued, the native path no longer builds a future and a handle for it.
ByteChannel.async_receive_bytes() lost data the same way: its wake-up callback took the bytes, so a task cancelled before it resumed dropped them. It now uses the term channel's loop, where the callback only wakes the task. The byte wait takes queued data before it reports a close, and no longer leaks the bytes it returns, a path every woken receive now takes.
The channel guide still showed the wake-up callback taking the message; it now shows the task taking it after the wake-up, what a cancel or a close means for queued messages, and that try_receive() cannot tell a queued none from an empty channel. The CHANGELOG entry covers both channel types. The isolated rejection test repeated py_isolated_SUITE, and the code map row goes back to what the module is.
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.
Supersedes #90 and keeps @h0rv's commit.
Awaiting a message on a channel could lose it. A message that was
nonearrives in Python asNone, which the receive took for an empty channel and skipped, on the Erlang event loop and on plain asyncio loops. On the Erlang event loop the wake-up callback took the message itself, so a task cancelled between the wake-up and its resume dropped it, on term and byte channels.The wake-up callback now only wakes the task, which takes the message with the existing wait call and registers again if it found nothing, so a cancelled task leaves the message queued. The wait hands over queued messages before it reports a close. A receive starts with a non-blocking receive that only fails when the channel is empty, so a queued
Nonecomes back like any other message, and a receive with data already queued costs what it did before. The byte wait also no longer leaks the bytes it returns.No breaking changes.