From 7560660ec7bacec86087fb7a50eb639afbdf3b08 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Fri, 24 Feb 2017 18:09:32 -0800 Subject: [PATCH] handle timeouts and disconnects properly --- sanic/websocket.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sanic/websocket.py b/sanic/websocket.py index 3fc0a092..a712eda8 100644 --- a/sanic/websocket.py +++ b/sanic/websocket.py @@ -10,6 +10,16 @@ class WebSocketProtocol(HttpProtocol): super().__init__(*args, **kwargs) self.websocket = None + def connection_timeout(self): + # timeouts make no sense for websocket routes + if self.websocket is None: + super().connection_timeout() + + def connection_lost(self, exc): + if self.websocket is not None: + self.websocket.connection_lost(exc) + super().connection_lost(exc) + def data_received(self, data): if self.websocket is not None: # pass the data to the websocket protocol