From df2369280246b98b06d4f7544b4c295867919453 Mon Sep 17 00:00:00 2001 From: andreymal Date: Fri, 19 Apr 2019 15:58:17 +0300 Subject: [PATCH 1/2] Fix graceful shutdown (the connections set was always empty in serve function) --- sanic/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/server.py b/sanic/server.py index bd0fdf37..f6d2cf28 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -119,7 +119,7 @@ class HttpProtocol(asyncio.Protocol): self.router = router self.signal = signal self.access_log = access_log - self.connections = connections or set() + self.connections = connections if connections is not None else set() self.request_handler = request_handler self.error_handler = error_handler self.request_timeout = request_timeout From 99e56ef74b288ef84bfe92276ac477d17f8c55a4 Mon Sep 17 00:00:00 2001 From: andreymal Date: Fri, 19 Apr 2019 16:00:01 +0300 Subject: [PATCH 2/2] Fix broken bail_out when HttpProtocol is closed --- sanic/server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index f6d2cf28..81b68cb5 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -554,11 +554,15 @@ class HttpProtocol(asyncio.Protocol): :return: None """ - if from_error or self.transport.is_closing(): + if from_error or self.transport is None or self.transport.is_closing(): logger.error( "Transport closed @ %s and exception " "experienced during error handling", - self.transport.get_extra_info("peername"), + ( + self.transport.get_extra_info("peername") + if self.transport is not None + else "N/A" + ), ) logger.debug("Exception:", exc_info=True) else: