Skip to content

Commit

Permalink
[PR #8271/e0d9d3ab backport][3.9] Fix race condition with request han…
Browse files Browse the repository at this point in the history
…dlers on shutdown (#8272)

**This is a backport of PR #8271 as merged into master
(e0d9d3a).**

Co-authored-by: Sam Bull <git@sambull.org>
  • Loading branch information
patchback[bot] and Dreamsorcerer authored Mar 31, 2024
1 parent 3a13bd5 commit 46e8f64
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 46e8f64

Please sign in to comment.