From 02cc56e605e5199b3dc796f9f7370d59d9cc104b Mon Sep 17 00:00:00 2001 From: PixeL Date: Mon, 22 Jan 2018 08:34:34 -0600 Subject: [PATCH 1/3] Handle zombie connections (#79) * Handle zombie connections * Close w/ non-1000 code, make variable private --- disco/gateway/client.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/disco/gateway/client.py b/disco/gateway/client.py index 92ad7ff..a7b5d36 100644 --- a/disco/gateway/client.py +++ b/disco/gateway/client.py @@ -40,6 +40,7 @@ class GatewayClient(LoggingClass): # Create emitter and bind to gateway payloads self.packets.on((RECV, OPCode.DISPATCH), self.handle_dispatch) self.packets.on((RECV, OPCode.HEARTBEAT), self.handle_heartbeat) + self.packets.on((RECV, OPCode.HEARTBEAT_ACK), self.handle_heartbeat_acknowledge) self.packets.on((RECV, OPCode.RECONNECT), self.handle_reconnect) self.packets.on((RECV, OPCode.INVALID_SESSION), self.handle_invalid_session) self.packets.on((RECV, OPCode.HELLO), self.handle_hello) @@ -67,6 +68,7 @@ class GatewayClient(LoggingClass): # Heartbeat self._heartbeat_task = None + self._heartbeat_acknowledged = True def send(self, op, data): self.limiter.check() @@ -82,7 +84,14 @@ class GatewayClient(LoggingClass): def heartbeat_task(self, interval): while True: + if not self._heartbeat_acknowledged: + self.log.warning('Received HEARTBEAT without HEARTBEAT_ACK, forcing a fresh reconnect') + self._heartbeat_acknowledged = True + self.ws.close(status=4000) + return + self._send(OPCode.HEARTBEAT, self.seq) + self._heartbeat_acknowledged = False gevent.sleep(interval / 1000) def handle_dispatch(self, packet): @@ -95,6 +104,10 @@ class GatewayClient(LoggingClass): def handle_heartbeat(self, _): self._send(OPCode.HEARTBEAT, self.seq) + def handle_heartbeat_acknowledge(self, _): + self.log.debug('Received HEARTBEAT_ACK') + self._heartbeat_acknowledged = True + def handle_reconnect(self, _): self.log.warning('Received RECONNECT request, forcing a fresh reconnect') self.session_id = None From ea6b882da71a637c99d86b70e67203879f0dab94 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 22 Jan 2018 06:30:50 -0800 Subject: [PATCH 2/3] [reqs] add wsaccel to performance reqs --- setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4c5a8a9..b9a0b6a 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,11 @@ extras_require = { 'http': ['flask==0.12.2'], 'yaml': ['pyyaml==3.12'], 'music': ['youtube_dl>=2018.1.14'], - 'performance': ['erlpack==0.3.2' if sys.version_info.major == 2 else 'earl-etf==2.1.2', 'ujson==1.35'], + 'performance': [ + 'erlpack==0.3.2' if sys.version_info.major == 2 else 'earl-etf==2.1.2', + 'ujson==1.35', + 'wsaccel==0.6.2', + ], 'sharding': ['gipc==0.6.0'], 'docs': ['biblio==0.0.4'], } From 9ac9e26a4a5feb1a308daf775c3a4924eae8a760 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 22 Jan 2018 07:57:09 -0800 Subject: [PATCH 3/3] [reqs] downgrade websocket-client to 0.44.0 There is some kind of issue with 0.46.0 causing weird gevent issues. Will have to investigate further in the future. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 59150ad..ce93f35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ gevent==1.2.2 holster==2.0.0 requests==2.18.4 six==1.11.0 -websocket-client==0.46.0 +websocket-client==0.44.0