@@ -303,9 +303,16 @@ def _detach(self, transport):
303
303
self ._wakeup ()
304
304
305
305
def _wakeup (self ):
306
- if self ._waiters is None :
307
- return
308
306
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
309
316
self ._waiters = None
310
317
for waiter in waiters :
311
318
if not waiter .done ():
@@ -949,7 +956,7 @@ async def sock_sendfile(self, sock, file, offset=0, count=None,
949
956
try :
950
957
return await self ._sock_sendfile_native (sock , file ,
951
958
offset , count )
952
- except exceptions .SendfileNotAvailableError as exc :
959
+ except exceptions .SendfileNotAvailableError :
953
960
if not fallback :
954
961
raise
955
962
return await self ._sock_sendfile_fallback (sock , file ,
@@ -1262,7 +1269,7 @@ async def sendfile(self, transport, file, offset=0, count=None,
1262
1269
try :
1263
1270
return await self ._sendfile_native (transport , file ,
1264
1271
offset , count )
1265
- except exceptions .SendfileNotAvailableError as exc :
1272
+ except exceptions .SendfileNotAvailableError :
1266
1273
if not fallback :
1267
1274
raise
1268
1275
0 commit comments