From 1f874fc2076541feeacff78f472fdddb01ccc0a7 Mon Sep 17 00:00:00 2001 From: stopdropandrew Date: Mon, 11 Dec 2023 11:43:39 -0800 Subject: [PATCH] Handle `asyncio.CancelledError` when socket is closed without flushing --- src/hypercorn/asyncio/tcp_server.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/hypercorn/asyncio/tcp_server.py b/src/hypercorn/asyncio/tcp_server.py index e90858b4..ed9d710f 100644 --- a/src/hypercorn/asyncio/tcp_server.py +++ b/src/hypercorn/asyncio/tcp_server.py @@ -115,7 +115,13 @@ async def _close(self) -> None: try: self.writer.close() await self.writer.wait_closed() - except (BrokenPipeError, ConnectionAbortedError, ConnectionResetError, RuntimeError): + except ( + BrokenPipeError, + ConnectionAbortedError, + ConnectionResetError, + RuntimeError, + asyncio.CancelledError, + ): pass # Already closed finally: await self._stop_idle()