Handle connection errors during auth key generation

This should help with spurious server-side disconnects during
auth_key generation, which happen most commonly on user DC
migrations.
This commit is contained in:
Lonami Exo 2019-10-24 13:48:29 +02:00
parent 08b78f0c47
commit 5dcc30dcc6

View File

@ -206,8 +206,23 @@ class MTProtoSender:
continue # skip auth key generation until we're connected continue # skip auth key generation until we're connected
if not self.auth_key: if not self.auth_key:
if not await self._try_gen_auth_key(attempt): try:
continue # keep retrying until we have the auth key if not await self._try_gen_auth_key(attempt):
continue # keep retrying until we have the auth key
except (IOError, asyncio.TimeoutError) as e:
# Sometimes, specially during user-DC migrations,
# Telegram may close the connection during auth_key
# generation. If that's the case, we will need to
# connect again.
self._log.warning('Connection error %d during auth_key gen: %s: %s',
attempt, type(e).__name__, e)
# Whatever the IOError was, make sure to disconnect so we can
# reconnect cleanly after.
await self._connection.disconnect()
connected = False
await asyncio.sleep(self._delay, loop=self._loop)
continue # next iteration we will try to reconnect
break # all steps done, break retry loop break # all steps done, break retry loop
else: else: