[3.11] gh-91227: Ignore ERROR_PORT_UNREACHABLE in proactor recvfrom() (GH-32011) (GH-117210)

(cherry picked from commit f11d0d8be8)

Co-authored-by: Erik Soma <stillusingirc@gmail.com>
This commit is contained in:
Serhiy Storchaka 2024-03-25 12:34:25 +02:00 committed by GitHub
parent a3a0ce1b2f
commit 6261322e26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 165 additions and 0 deletions

View file

@ -513,6 +513,10 @@ class IocpProactor:
try:
return ov.getresult()
except OSError as exc:
# WSARecvFrom will report ERROR_PORT_UNREACHABLE when the same
# socket is used to send to an address that is not listening.
if exc.winerror == _overlapped.ERROR_PORT_UNREACHABLE:
return b'', None
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
_overlapped.ERROR_OPERATION_ABORTED):
raise ConnectionResetError(*exc.args)
@ -533,6 +537,10 @@ class IocpProactor:
try:
return ov.getresult()
except OSError as exc:
# WSARecvFrom will report ERROR_PORT_UNREACHABLE when the same
# socket is used to send to an address that is not listening.
if exc.winerror == _overlapped.ERROR_PORT_UNREACHABLE:
return 0, None
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
_overlapped.ERROR_OPERATION_ABORTED):
raise ConnectionResetError(*exc.args)