8000 gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times by Fidget-Spinner · Pull Request #98704 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-98703: Fix asyncio proactor_events calling _call_connection_lost multiple times #98704

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
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
Fix asyncio proactor_events calling _call_connection_lost multiple times
  • Loading branch information
Fidget-Spinner committed Oct 26, 2022
commit f348542fa49e3a395304f5b22c53a8504ba98b7b
7 changes: 6 additions & 1 deletion Lib/asyncio/proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self, loop, sock, protocol, waiter=None,
super().__init__(extra, loop)
self._set_extra(sock)
self._sock = sock
self._sock_called_close = False
self.set_protocol(protocol)
self._server = server
self._buffer = None # None or bytearray.
Expand Down Expand Up @@ -161,8 +162,12 @@ def _call_connection_lost(self, exc):
# cure it, but maybe using DisconnectEx() would be better.
if hasattr(self._sock, 'shutdown') and self._sock.fileno() != -1:
self._sock.shutdown(socket.SHUT_RDWR)
self._sock.close()
# We can't call sock._close() indiscriminately because something
# else might be calling _call_connection_lost again.
if not self._sock_called_close:
self._sock.close()
self._sock = None
self._sock_called_close = True
server = self._server
if server is not None:
server._detach()
Expand Down
0