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():
|
while not self.is_closed():
|
||||||
try:
|
try:
|
||||||
yield from self._connect()
|
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,
|
except (HTTPException,
|
||||||
GatewayNotFound,
|
GatewayNotFound,
|
||||||
|
ConnectionClosed,
|
||||||
aiohttp.ClientError,
|
aiohttp.ClientError,
|
||||||
asyncio.TimeoutError,
|
asyncio.TimeoutError,
|
||||||
websockets.InvalidHandshake,
|
websockets.InvalidHandshake,
|
||||||
@ -404,6 +398,15 @@ class Client:
|
|||||||
yield from self.close()
|
yield from self.close()
|
||||||
raise
|
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()
|
retry = backoff.delay()
|
||||||
log.exception("Attempting a reconnect in {:.2f}s".format(retry))
|
log.exception("Attempting a reconnect in {:.2f}s".format(retry))
|
||||||
yield from asyncio.sleep(retry, loop=self.loop)
|
yield from asyncio.sleep(retry, loop=self.loop)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user