Skip to content

Commit d963237

Browse files
fix: Add comments and use existing waiter ref
1 parent 2eb9556 commit d963237

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Lib/asyncio/base_events.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,16 @@ def _detach(self, transport):
303303
self._wakeup()
304304

305305
def _wakeup(self):
306-
if self._waiters is None:
307-
return
308306
waiters = self._waiters
307+
if waiters is None:
308+
# gh109564: the wakeup method has two possible call-sites, through an
309+
# explicit call to the server's close method, or indirectly after the last
310+
# client disconnects and the corresponding transport detaches from the
311+
# server. These two can be in a race-condition if the server closes between
312+
# `BaseSelectorEventLoop._accept_connection` and
313+
# `BaseSelectorEventLoop._accept_connection2`; in this scenario we must
314+
# check the wakeup call hasn't already set the server waiters to None.
315+
return
309316
self._waiters = None
310317
for waiter in waiters:
311318
if not waiter.done():
@@ -949,7 +956,7 @@ async def sock_sendfile(self, sock, file, offset=0, count=None,
949956
try:
950957
return await self._sock_sendfile_native(sock, file,
951958
offset, count)
952-
except exceptions.SendfileNotAvailableError as exc:
959+
except exceptions.SendfileNotAvailableError:
953960
if not fallback:
954961
raise
955962
return await self._sock_sendfile_fallback(sock, file,
@@ -1262,7 +1269,7 @@ async def sendfile(self, transport, file, offset=0, count=None,
12621269
try:
12631270
return await self._sendfile_native(transport, file,
12641271
offset, count)
1265-
except exceptions.SendfileNotAvailableError as exc:
1272+
except exceptions.SendfileNotAvailableError:
12661273
if not fallback:
12671274
raise
12681275

0 commit comments

Comments
 (0)