don't silently discard UDP errors - #1295
Draft
graingert wants to merge 16 commits into
Draft
Conversation
graingert
marked this pull request as ready for review
August 26, 2026 09:10
graingert
marked this pull request as draft
August 26, 2026 09:14
graingert
force-pushed
the
error-recieved-udp
branch
2 times, most recently
from
August 26, 2026 09:43
c48ad66 to
430c246
Compare
graingert
marked this pull request as ready for review
August 26, 2026 16:18
graingert
force-pushed
the
error-recieved-udp
branch
from
August 27, 2026 07:37
8653582 to
8ed6b23
Compare
Collaborator
Author
graingert
marked this pull request as draft
August 27, 2026 07:42
graingert
force-pushed
the
error-recieved-udp
branch
2 times, most recently
from
August 27, 2026 12:41
99dc210 to
6523920
Compare
graingert
force-pushed
the
error-recieved-udp
branch
from
August 27, 2026 13:59
6523920 to
2c0676c
Compare
Errors reported by the transport overwrote each other, so a burst of OS errors lost all but the last one. Queue them instead, popping the oldest first, and only restore the write back-pressure once the queue drains. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
graingert
force-pushed
the
error-recieved-udp
branch
from
August 28, 2026 09:26
7d00f20 to
fa49f25
Compare
A send() cancelled while blocked on the post-send wait leaves its datagram in the asyncio transport's buffer with the protocol still paused. Without a wait before sendto(), the next send() hands its datagram straight to the transport, which appends it to that non-empty buffer without ever trying the OS, so repeated cancellation grows the buffer despite the zero high water mark. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
# Conflicts: # tests/test_sockets.py
error_received() sets the write event while the transport is still paused, so that a sender blocked on it can raise the error. If a concurrent receive() claims that error first, take_exception() re-clears the event, but a sender already released from the pre-send wait didn't re-check: it went on to hand its datagram to a paused transport, which only appends it to its buffer without ever offering it to the OS. Guard the pre-send wait with the same write_paused loop the post-send wait uses, so the pause flag, rather than the event, decides when it's safe to send. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
# Conflicts: # src/anyio/_backends/_asyncio.py
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Unlike Trio, which runs a cancel_shielded_checkpoint() on the way out of a failed socket call, the closed and broken paths now only get the checkpoint_if_cancelled() at the top. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
# Conflicts: # src/anyio/_backends/_asyncio.py
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.
NOTE Erasing or replacing the contents of this template will result in your pull
request being summarily closed without consideration!
Changes
Fixed UDP sockets on the asyncio backend silently discarding errors reported by the OS (such as an ICMP port unreachable). A task blocked in
receive()orsend()is now woken up by such an error, and both raiseBrokenResourceError, chained to the original error, as they already did on the Trio backend. As on the Trio backend, the error is only reported once, leaving the socket usable afterwardsChecklist
If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):
tests/) which would fail without your patchdocs/), in case of behavior changes or newfeatures
docs/versionhistory.rst).If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.
Updating the changelog
If there are no entries after the last release, use
**UNRELEASED**as the version.If, say, your patch fixes issue #123, the entry should look like this:
If there's no issue linked, just link to your pull request instead by updating the
changelog after you've created the PR.