mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-21 00:07:51 +00:00
Reconnect even if we close with 1000 since Discord can send it.
Rely on is_closed() instead since this is the true metric of a clean closure.
This commit is contained in:
parent
e78a5c0643
commit
5ce88c8a3f
@ -386,15 +386,9 @@ class Client:
|
||||
while not self.is_closed():
|
||||
try:
|
||||
yield from self._connect()
|
||||
except ConnectionClosed as e:
|
||||
# We should only get this when an unhandled close code happens,
|
||||
# such as a clean disconnect (1000) or a bad state (bad token, no sharding, etc)
|
||||
# in both cases we should just terminate our connection.
|
||||
yield from self.close()
|
||||
if e.code != 1000:
|
||||
raise
|
||||
except (HTTPException,
|
||||
GatewayNotFound,
|
||||
ConnectionClosed,
|
||||
aiohttp.ClientError,
|
||||
asyncio.TimeoutError,
|
||||
websockets.InvalidHandshake,
|
||||
@ -404,6 +398,15 @@ class Client:
|
||||
yield from self.close()
|
||||
raise
|
||||
|
||||
# We should only get this when an unhandled close code happens,
|
||||
# such as a clean disconnect (1000) or a bad state (bad token, no sharding, etc)
|
||||
# sometimes, discord sends us 1000 for unknown reasons so we should reconnect
|
||||
# regardless and rely on is_closed instead
|
||||
if isinstance(e, ConnectionClosed):
|
||||
if e.code != 1000:
|
||||
yield from self.close()
|
||||
raise
|
||||
|
||||
retry = backoff.delay()
|
||||
log.exception("Attempting a reconnect in {:.2f}s".format(retry))
|
||||
yield from asyncio.sleep(retry, loop=self.loop)
|
||||
|
Loading…
x
Reference in New Issue
Block a user