bpo-41317: Remove reader on cancellation in asyncio.loop.sock_accept() (GH-21595)

(cherry picked from commit 0dd98c2d00)

Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
This commit is contained in:
Miss Islington (bot) 2020-07-23 13:02:47 -07:00 committed by GitHub
parent e8dda907fb
commit 4ff8e5ba4f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 7 deletions

View file

@ -555,20 +555,19 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
if self._debug and sock.gettimeout() != 0:
raise ValueError("the socket must be non-blocking")
fut = self.create_future()
self._sock_accept(fut, False, sock)
self._sock_accept(fut, sock)
return await fut
def _sock_accept(self, fut, registered, sock):
def _sock_accept(self, fut, sock):
fd = sock.fileno()
if registered:
self.remove_reader(fd)
if fut.done():
return
try:
conn, address = sock.accept()
conn.setblocking(False)
except (BlockingIOError, InterruptedError):
self.add_reader(fd, self._sock_accept, fut, True, sock)
self._ensure_fd_no_transport(fd)
handle = self._add_reader(fd, self._sock_accept, fut, sock)
fut.add_done_callback(
functools.partial(self._sock_read_done, fd, handle=handle))
except (SystemExit, KeyboardInterrupt):
raise
except BaseException as exc: