Skip to content

CI probe (control): #1246's UDP fix reverted - #2

Closed
graingert-coef wants to merge 9 commits into
masterfrom
test/udp-aclose-probe-unfixed
Closed

CI probe (control): #1246's UDP fix reverted#2
graingert-coef wants to merge 9 commits into
masterfrom
test/udp-aclose-probe-unfixed

Conversation

@graingert-coef

Copy link
Copy Markdown
Owner

Not for merge — control run for #1.

Identical to #1 except UDPSocket.aclose() / ConnectedUDPSocket.aclose() have PR 1246's abort() + shielded checkpoint removed, so the wait on closed_event is unshielded again.

Prediction

test_aclose_forcefully_with_pending_send (both UDP classes) times out on windows-latest, and passes everywhere else.

Mechanism: _ProactorDatagramTransport.sendto() starts an overlapped op, so close() skips scheduling connection_lost while _write_fut is pending (proactor_events.py:108). close() also increments _conn_lost, so when the completion lands _loop_writing() returns at if self._conn_lost: return (:513) before reaching the if self._closing: call_soon(_call_connection_lost) at :524. connection_lost is therefore never called, closed_event is never set, and the wait blocks forever. agronholm#1246's abort() fixes it by routing through _force_close, where the call_soon is unconditional (:152).

My earlier version of these tests passed on Windows for the wrong reason: it entered a task group between the send and the close, and that one event loop iteration was enough for the proactor to reap the overlapped send.

If this run passes on Windows, the mechanism above is wrong and agronholm#1246 fixes something else.

Guflly and others added 9 commits July 27, 2026 00:06
Extends the TCP regression test from agronholm#1277 to UDPSocket, ConnectedUDPSocket
and Process.

The plain variants pass on master too, so they are guards rather than
regression tests. The pending-send variants target Windows specifically:
_ProactorDatagramTransport.sendto() always buffers and starts an overlapped
operation, so transport.close() declines to schedule connection_lost while
_write_fut is pending, deferring it to an IOCP completion on a later loop
iteration. That should expose UDPSocket.aclose()'s unshielded wait on
closed_event, which is invisible on selector loops.

Pushed to run the Windows CI matrix; not intended for upstream as-is.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/anyio/_backends/_asyncio.py
The previous versions queued sends and then entered a task group, but
start_soon() only schedules — the children first run when the host yields at
__aexit__, and one event loop iteration is all the proactor needs to reap the
overlapped send. close() then took the no-pending-write path and the tests
passed on Windows for the wrong reason.

anyio puts send()'s checkpoint before transport.sendto(), so the operation is
only still in flight if nothing yields afterwards. Drop the pointless 10x send
loop (each iteration yielded, so the buffer drained every time) and close
directly after a single send, as PR agronholm#1246's own reproducer does.

Adds a concurrent variant gated on an Event so the second closer only runs once
the first has yielded inside aclose(), which is where its unshielded wait on
closed_event is exposed. Neither PR covers that caller.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Control for the pending-send tests: with abort() and the shielded checkpoint
removed from UDPSocket.aclose() and ConnectedUDPSocket.aclose(), the wait on
closed_event is unshielded again and transport.close() is the only thing
scheduling connection_lost. Expected to time out on Windows.

Not for merge.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@graingert-coef

Copy link
Copy Markdown
Owner Author

Control run complete — result recorded. With agronholm#1246's UDP aclose() fix reverted, Windows (stock proactor asyncio and asyncio+eager, ipv4) gives 14 failures vs 1 on the fixed branch:

  • test_aclose_forcefully_with_pending_sendAssertionError: assert 2344 == -1 (early return, live FD)
  • TestConnectedUDPSocket::test_aclose_during_sendTimeoutError (hang)

Both modes are the same defect; the call path decides which one you see. Under aclose_forcefully() the unshielded closed_event.wait() is cancelled and returns with the FD open; under plain aclose() it blocks on an event that never gets set, because close() increments _conn_lost and _loop_writing() then bails at proactor_events.py:513 before reaching the call_soon(_call_connection_lost) at :524. winloop/rsloop are unaffected, being libuv-based rather than proactor.

Closing — superseded by #1.

@graingert-coef
graingert-coef deleted the test/udp-aclose-probe-unfixed branch August 13, 2026 10:14
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.

3 participants