aboutsummaryrefslogtreecommitdiff
path: root/discord/gateway.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2020-05-03 01:28:29 -0400
committerRapptz <[email protected]>2020-07-25 09:59:40 -0400
commite2f42597a5d81c048ac926c434e81f3997fedb7e (patch)
tree730c834e44e7144dcdafedeb8ec5dbbef08d0209 /discord/gateway.py
parentAdd shard related connection and resume events. (diff)
downloaddiscord.py-e2f42597a5d81c048ac926c434e81f3997fedb7e.tar.xz
discord.py-e2f42597a5d81c048ac926c434e81f3997fedb7e.zip
Handle Connection Reset by Peer connection errors.
This should work both on Windows and on Linux. Apparently these types of blips are considered normal for Discord. So rather than letting the reconnect logic handler expect these to be catastrophic, it should handle it specially so it doesn't waste an IDENTIFY for what ultimately should just be a small networking blip. This also makes it less noisy for the end-user as these complaints happen from time to time.
Diffstat (limited to 'discord/gateway.py')
-rw-r--r--discord/gateway.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/discord/gateway.py b/discord/gateway.py
index 3f92ec1f..f262477f 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -508,16 +508,21 @@ class DiscordWebSocket:
elif msg.type is aiohttp.WSMsgType.ERROR:
log.debug('Received %s', msg)
raise msg.data
- elif msg.type in (aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSE):
+ elif msg.type in (aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSING, aiohttp.WSMsgType.CLOSE):
log.debug('Received %s', msg)
raise WebSocketClosure
- except WebSocketClosure as e:
+ except WebSocketClosure:
+ # Ensure the keep alive handler is closed
+ if self._keep_alive:
+ self._keep_alive.stop()
+ self._keep_alive = None
+
if self._can_handle_close():
log.info('Websocket closed with %s, attempting a reconnect.', self.socket.close_code)
- raise ReconnectWebSocket(self.shard_id) from e
+ raise ReconnectWebSocket(self.shard_id) from None
elif self.socket.close_code is not None:
log.info('Websocket closed with %s, cannot reconnect.', self.socket.close_code)
- raise ConnectionClosed(self.socket, shard_id=self.shard_id) from e
+ raise ConnectionClosed(self.socket, shard_id=self.shard_id) from None
async def send(self, data):
self._dispatch('socket_raw_send', data)
@@ -598,6 +603,7 @@ class DiscordWebSocket:
async def close(self, code=4000):
if self._keep_alive:
self._keep_alive.stop()
+ self._keep_alive = None
await self.socket.close(code=code)