Skip to content

Stop losing channel messages on None payloads and cancelled receivers - #91

Merged
benoitc merged 4 commits into
mainfrom
fix/channel-none-payload
Nov 26, 2026
Merged

benoitc merged 4 commits into
mainfrom
fix/channel-none-payload

Conversation

@benoitc

@benoitc benoitc commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Supersedes #90 and keeps @h0rv's commit.

Awaiting a message on a channel could lose it. A message that was none arrives in Python as None, 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 None comes 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.

h0rv and others added 4 commits November 26, 2026 22:34
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.
@benoitc
benoitc merged commit 80adedf into main Nov 26, 2026
20 checks passed
@benoitc
benoitc deleted the fix/channel-none-payload branch November 26, 2026 22:43
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.

2 participants