Skip to content

Commit

Permalink
Fix race condition with request handlers on shutdown (#8271)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Mar 30, 2024
1 parent 509fb26 commit e0d9d3a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/8271.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a race condition with incoming connections during server shutdown -- by :user:`Dreamsorcerer`.
3 changes: 3 additions & 0 deletions aiohttp/web_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ async def cleanup(self) -> None:
await site.stop()

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

Expand Down

0 comments on commit e0d9d3a

Please sign in to comment.