From 83fb1793ff152a9ddcb7859edad0532908120719 Mon Sep 17 00:00:00 2001 From: Taha Jahangir Date: Wed, 28 Sep 2016 18:10:04 +0330 Subject: [PATCH] Close idle keep-alive connections on shutdown Fixing #1221 --- aiohttp/server.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aiohttp/server.py b/aiohttp/server.py index 9223a1f9d14..258580c63cd 100644 --- a/aiohttp/server.py +++ b/aiohttp/server.py @@ -154,7 +154,10 @@ def shutdown(self, timeout=15.0): return self._closing = True - if timeout: + if self._request_count > 1 and not self._reading_request: + # force-close idle keep-alive connections + self._request_handler.cancel() + elif timeout: canceller = self._loop.call_later(timeout, self._request_handler.cancel) with suppress(asyncio.CancelledError):