From d2d6008eec2ab1695dd01fcb25e402b2ca398d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Tue, 10 Mar 2020 15:23:22 +0200 Subject: [PATCH] Need to check if transport is closing to avoid getting stuck in sending loops after peer has disconnected. --- sanic/server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sanic/server.py b/sanic/server.py index c0c5ff4a..cdea56dd 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -184,6 +184,8 @@ class HttpProtocol(asyncio.Protocol): async def send(self, data): """Writes data with backpressure control.""" await self._can_write.wait() + if self.transport.is_closing(): + raise CancelledError self.transport.write(data) self._time = current_time()