Skip to content

Commit e0d9d3a

Browse files
Fix race condition with request handlers on shutdown (#8271)
1 parent 509fb26 commit e0d9d3a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

CHANGES/8271.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a race condition with incoming connections during server shutdown -- by :user:`Dreamsorcerer`.

aiohttp/web_runner.py

+3
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ async def cleanup(self) -> None:
299299
await site.stop()
300300

301301
if self._server: # If setup succeeded
302+
# Yield to event loop to ensure incoming requests prior to stopping the sites
303+
# have all started to be handled before we proceed to close idle connections.
304+
await asyncio.sleep(0)
302305
self._server.pre_shutdown()
303306
await self.shutdown()
304307

0 commit comments

Comments
 (0)