Skip to content

Preserve native channel deliveries across None payloads and cancellation - #90

Open
h0rv wants to merge 1 commit into
benoitc:mainfrom
h0rv:fix/channel-none-payload
Open

h0rv wants to merge 1 commit into
benoitc:mainfrom
h0rv:fix/channel-none-payload

Conversation

@h0rv

@h0rv h0rv commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

A queued none sent from Erlang became Python None, which the native async receive fast path treated as an empty queue. It consumed the message and then waited for another. A readiness callback also dequeued a message before waking the receiving task, so cancelling the task between notification and resumption lost that delivery.

With a channel reference passed to Python, the first receive below timed out:

{ok, Ch} = py_channel:new(),
ok = py_channel:send(Ch, none).
import asyncio
import erlang

async def receive(ref):
    result = await asyncio.wait_for(erlang.Channel(ref).async_receive(), 1)
    assert result is None

Native async receive now uses the existing tagged _channel_wait result instead of the ambiguous try_receive result. The callback signals readiness only; the task retries the atomic dequeue-or-register operation after resuming. A cancelled task therefore leaves the data queued. Native waiting stays native after an empty notification. The wait helper drains queued data before reporting closure, as the previous fast path did.

No public signature changes. Non-native asyncio's executor fallback and synchronous try_receive semantics are unchanged. Channels remain explicitly unsupported in isolated contexts.

OTP 28.3, conventional Python 3.12.16:

  • Before: native_none_payload_test failed with TimeoutError; native_cancel_ready_test failed with AssertionError; isolated rejection passed.
  • After: channel and byte-channel suites: All 55 tests passed.
  • The None regression covers queued and delayed payloads. The cancellation regression runs the actual registered readiness handle before cancelling the task, fixing the interleaving rather than relying on timing.
  • rebar3 dialyzer, rebar3 xref: exit 0.
  • make lint-docs check-code-map: lint-docs: clean (35 file(s)); check_code_map: clean.

Unmodified upstream baseline: 127 tests passed across channel, byte-channel, event-loop, pool, thread-callback, reentrant and callback-encoding suites.

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