From e2f42597a5d81c048ac926c434e81f3997fedb7e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 3 May 2020 01:28:29 -0400 Subject: 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. --- discord/shard.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'discord/shard.py') diff --git a/discord/shard.py b/discord/shard.py index dfa3849c..7659e5ec 100644 --- a/discord/shard.py +++ b/discord/shard.py @@ -112,6 +112,12 @@ class Shard: if self._client.is_closed(): return + if isinstance(e, OSError) and e.errno in (54, 10054): + # If we get Connection reset by peer then always try to RESUME the connection. + exc = ReconnectWebSocket(self.id, resume=True) + self._queue.put_nowait(EventItem(EventType.resume, self, exc)) + return + if isinstance(e, ConnectionClosed): if e.code != 1000: self._queue.put_nowait(EventItem(EventType.close, self, e)) @@ -142,7 +148,7 @@ class Shard: try: coro = DiscordWebSocket.from_client(self._client, resume=exc.resume, shard_id=self.id, session=self.ws.session_id, sequence=self.ws.sequence) - self.ws = await asyncio.wait_for(coro, timeout=180.0) + self.ws = await asyncio.wait_for(coro, timeout=60.0) except self._handled_exceptions as e: await self._handle_disconnect(e) else: @@ -152,7 +158,7 @@ class Shard: self._cancel_task() try: coro = DiscordWebSocket.from_client(self._client, shard_id=self.id) - self.ws = await asyncio.wait_for(coro, timeout=180.0) + self.ws = await asyncio.wait_for(coro, timeout=60.0) except self._handled_exceptions as e: await self._handle_disconnect(e) else: -- cgit v1.2.3