From 173617ad3b2a38c37cba3a0f76bb9767d535f106 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Fri, 16 Feb 2018 09:56:40 -0800 Subject: [PATCH] Fixed #172: Outgoing frames do not reset ping clock (incoming does) --- daphne/ws_protocol.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/daphne/ws_protocol.py b/daphne/ws_protocol.py index 2792662..15ce550 100755 --- a/daphne/ws_protocol.py +++ b/daphne/ws_protocol.py @@ -28,7 +28,7 @@ class WebSocketProtocol(WebSocketServerProtocol): self.request = request self.protocol_to_accept = None self.socket_opened = time.time() - self.last_data = time.time() + self.last_ping = time.time() try: # Sanitize and decode headers self.clean_headers = [] @@ -108,7 +108,7 @@ class WebSocketProtocol(WebSocketServerProtocol): logger.debug("Muting incoming frame on %s", self.client_addr) return logger.debug("WebSocket incoming frame on %s", self.client_addr) - self.last_data = time.time() + self.last_ping = time.time() if isBinary: self.application_queue.put_nowait({ "type": "websocket.receive", @@ -200,7 +200,6 @@ class WebSocketProtocol(WebSocketServerProtocol): """ if self.state == self.STATE_CONNECTING: self.serverAccept() - self.last_data = time.time() logger.debug("Sent WebSocket packet to client for %s", self.client_addr) if binary: self.sendMessage(content, binary) @@ -235,9 +234,9 @@ class WebSocketProtocol(WebSocketServerProtocol): if self.duration() > self.server.websocket_connect_timeout: self.serverReject() elif self.state == self.STATE_OPEN: - if (time.time() - self.last_data) > self.server.ping_interval: + if (time.time() - self.last_ping) > self.server.ping_interval: self._sendAutoPing() - self.last_data = time.time() + self.last_ping = time.time() def __hash__(self): return hash(id(self))