From de65f7309bc8f8c931f29dcd76ebd9e8b0ee547b Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 8 Aug 2017 21:12:04 -0400 Subject: Add heartbeat_timeout to the Client options. This setting configures how long before a timeout event is emitted internally and disconnects the websocket. Since some users were experiencing issues with the gateway not responding, this should help mitigate the issue for those with poor PCs. --- discord/gateway.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'discord/gateway.py') diff --git a/discord/gateway.py b/discord/gateway.py index d5ddb9eb..50104034 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -64,10 +64,11 @@ class KeepAliveHandler(threading.Thread): self._stop_ev = threading.Event() self._last_ack = time.time() self._last_send = time.time() + self.heartbeat_timeout = ws._max_heartbeat_timeout def run(self): while not self._stop_ev.wait(self.interval): - if self._last_ack + 2 * self.interval < time.time(): + if self._last_ack + self.heartbeat_timeout < time.time(): log.warn("Shard ID %s has stopped responding to the gateway. Closing and restarting." % self.shard_id) coro = self.ws.close(1006) f = compat.run_coroutine_threadsafe(coro, loop=self.ws.loop) @@ -205,6 +206,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): ws.shard_count = client._connection.shard_count ws.session_id = session ws.sequence = sequence + ws._max_heartbeat_timeout = client._connection.heartbeat_timeout client._connection._update_references(ws) @@ -590,6 +592,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol): ws = yield from websockets.connect(gateway, loop=client.loop, klass=cls) ws.gateway = gateway ws._connection = client + ws._max_heartbeat_timeout = 60.0 if resume: yield from ws.resume() -- cgit v1.2.3