Skip to content

Commit 15d44ad

Browse files
committed
Fix bug that when accepting a socket connection and ERROR_NETNAME_DELETED occurs, leads this into a closing of the serving socket
This is done with the patches described by fercod in the GitHub thread #93821. These patches were successfully tested by me and worked properly. The error propagates properly without closing the original socket and without causing the server to hang.
1 parent 6e06e01 commit 15d44ad

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎Lib/asyncio/proactor_events.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ def loop(f=None):
858858
if self.is_closed():
859859
return
860860
f = self._proactor.accept(sock)
861+
except ConnectionResetError:
862+
self.call_soon(loop)
861863
except OSError as exc:
862864
if sock.fileno() != -1:
863865
self.call_exception_handler({

‎Lib/asyncio/windows_events.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,16 @@ def accept(self, listener):
553553
ov.AcceptEx(listener.fileno(), conn.fileno())
554554

555555
def finish_accept(trans, key, ov):
556-
ov.getresult()
556+
try:
557+
ov.getresult()
558+
except OSError as exc:
559+
# Fix bug when accepting a socket connection and ERROR_NETNAME_DELETED
560+
# occurs, leads this into a closing of the serving socket.
561+
if exc.winerror in (_overlapped.ERROR_NETNAME_DELETED,
562+
_overlapped.ERROR_OPERATION_ABORTED):
563+
conn.close()
564+
raise ConnectionResetError(*exc.args)
565+
raise
557566
# Use SO_UPDATE_ACCEPT_CONTEXT so getsockname() etc work.
558567
buf = struct.pack('@P', listener.fileno())
559568
conn.setsockopt(socket.SOL_SOCKET,

0 commit comments

Comments
 (0)