Browse Source

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.
pull/476/merge
Rapptz 8 years ago
parent
commit
5ce88c8a3f
  1. 17
      discord/client.py

17
discord/client.py

@ -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…
Cancel
Save