This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: asyncio proactor udp transport stops responding after send to port that isn't listening
Type: Stage: patch review
Components: asyncio, Windows Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, esoma, paul.moore, steve.dower, tim.golden, yselivanov, zach.ware
Priority: normal Keywords: patch

Created on 2022-03-20 14:58 by esoma, last changed 2022-04-11 14:59 by admin.

File name Uploaded Description Edit esoma, 2022-03-20 14:58 esoma, 2022-03-20 15:00
Pull Requests
URL Status Linked Edit
PR 32011 open esoma, 2022-03-20 15:48
Messages (4)
msg415611 - (view) Author: Erik Soma (esoma) * Date: 2022-03-20 14:58
Reproducer attached. Change `USE_PROACTOR` to `False` to use the `SelectorEventLoop` instead, which doesn't exhibit this behavior.

The output on my machine when using the proactor loop is:
datagram received b'ping 1'
datagram received b'ping 2'

And the selector loop (which is the behavior I would expect):
datagram received b'ping 1'
datagram received b'ping 2'
datagram received b'ping 3'

At a high level, after sending data to an address that isn't listening the asyncio protocol will no longer receive messages.

Digging deeper, `_ProactorDatagramTransport._loop_reading` encounters the windows error 1234 (ERROR_PORT_UNREACHABLE) after the "bad send". It appears this a (undocumented/buggy?) behavior of `WSARecvFrom` where the next call to it after an unreachable `WSASendTo` in UDP mode will return the ICMP unreachable message. The actual error is returned from `GetOverlappedResult`.

I've hacked together a fix that retries `IocpProactor.recvfrom` if the result is ERROR_PORT_UNREACHABLE. It fixes the issue for the reproducer and my actual use case, but it's probably not ideal. My solution for the moment is just to use the SelectorEventLoop instead.
msg415612 - (view) Author: Erik Soma (esoma) * Date: 2022-03-20 15:00
Uploading my hack to `` -- this is based off 3.10.2's distribution.
msg415614 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-20 15:38
Thanks for the report.
Could you make a pull request?
The whole attached is hard to analyze.
msg415617 - (view) Author: Erik Soma (esoma) * Date: 2022-03-20 15:48
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91227
2022-03-20 15:48:54esomasetmessages: + msg415617
2022-03-20 15:48:18esomasetkeywords: + patch
stage: patch review
pull_requests: + pull_request30099
2022-03-20 15:38:09asvetlovsetmessages: + msg415614
2022-03-20 15:00:21esomasetfiles: +

messages: + msg415612
2022-03-20 14:58:17esomacreate