mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-10-22 00:13:01 +00:00
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.
This commit is contained in:
@@ -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:
|
||||
|
Reference in New Issue
Block a user