8000 gh-91227: Ignore ERROR_PORT_UNREACHABLE by esoma · Pull Request #32011 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-91227: Ignore ERROR_PORT_UNREACHABLE #32011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Retry recvfrom when ERROR_PORT_UNREACHABLE received.
  • Loading branch information
esoma committed Mar 20, 2022
commit e184e95cc04052934fc27524ab54e2c4fa815ee2
26 changes: 24 additions & 2 deletions Lib/asyncio/windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@
CONNECT_PIPE_MAX_DELAY = 0.100


class _Retry(RuntimeError):

def __init__(self, ov, obj, callback):
super().__init__()
self.ov = ov
self.obj = obj
self.callback = callback


class _OverlappedFuture(futures.Future):
"""Subclass of Future which represents an overlapped operation.

Expand Down Expand Up @@ -493,6 +502,9 @@ def finish_recv(trans, key, ov):
return self._register(ov, conn, finish_recv)

def recvfrom(self, conn, nbytes, flags=0):
return self._register(*self._recvfrom(conn, nbytes, flags))

def _recvfrom(self, conn, nbytes, flags):
self._register_with_iocp(conn)
ov = _overlapped.Overlapped(NULL)
try:
Expand All @@ -504,13 +516,15 @@ def finish_recv(trans, key, ov):
try:
return ov.getresult()
except OSError as exc:
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
if exc.winerror == 1234: # ERROR_PORT_UNREACHABLE
raise _Retry(*self._recvfrom(conn, nbytes, flags))
elif exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
_overlapped.ERROR_OPERATION_ABORTED):
raise ConnectionResetError(*exc.args)
else:
raise

return self._register(ov, conn, finish_recv)
return ov, conn, finish_recv

def recvfrom_into(self, conn, buf, flags=0):
self._register_with_iocp(conn)
Expand Down Expand Up @@ -835,6 +849,14 @@ def _poll(self, timeout=None):
elif not f.done():
try:
value = callback(transferred, key, ov)
except _Retry as retry:
self._cache[retry.ov.address] = (
f,
retry.ov,
retry.obj,
retry.callback
)
continue
except OSError as e:
f.set_exception(e)
self._results.append(f)
Expand Down
0