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
(cherry picked from commit e0d9d3a)
  • Loading branch information
Dreamsorcerer authored and patchback[bot] committed Mar 30, 2024
1 parent 3a13bd5 commit 651f970
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 @@ -307,6 +307,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 651f970

Please sign in to comment.