Skip to content

Commit 46e8f64

Browse files
[PR #8271/e0d9d3ab backport][3.9] Fix race condition with request handlers on shutdown (#8272)
**This is a backport of PR #8271 as merged into master (e0d9d3a).** Co-authored-by: Sam Bull <[email protected]>
1 parent 3a13bd5 commit 46e8f64

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
@@ -307,6 +307,9 @@ async def cleanup(self) -> None:
307307
await site.stop()
308308

309309
if self._server: # If setup succeeded
310+
# Yield to event loop to ensure incoming requests prior to stopping the sites
311+
# have all started to be handled before we proceed to close idle connections.
312+
await asyncio.sleep(0)
310313
self._server.pre_shutdown()
311314
await self.shutdown()
312315

0 commit comments

Comments
 (0)