Skip to content

Commit

Permalink
Fix server shutdown on Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
bmerry committed Sep 19, 2023
1 parent 7afcc19 commit 2cb0012
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/aiokatcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,14 @@ async def _stop_impl(self, cancel: bool = True) -> None:
self._stop_task = asyncio.current_task()
if self._server is not None:
self._server.close()
await self._server.wait_closed()
# Workaround for race condition: we need any connections
# that were started before the listening socket was closed
# to be fully established, so that we can shut them down
# properly, and that may take several event loop iterations.
# See https://github.com/python/cpython/issues/109564 for
# more information.
for _ in range(10):
await asyncio.sleep(0)
self._server = None
if self._pending:
for task in self._pending:
Expand Down

0 comments on commit 2cb0012

Please sign in to comment.