mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Unify retry loops in mtprotosender._connect
Now the retry count is not twice its value.
This commit is contained in:
parent
3039915ce9
commit
08b78f0c47
|
@ -197,17 +197,23 @@ class MTProtoSender:
|
|||
receive loops.
|
||||
"""
|
||||
self._log.info('Connecting to %s...', self._connection)
|
||||
|
||||
connected = False
|
||||
for attempt in retry_range(self._retries):
|
||||
if await self._try_connect(attempt):
|
||||
break
|
||||
else:
|
||||
raise ConnectionError('Connection to Telegram failed %d time(s)', self._retries)
|
||||
if not connected:
|
||||
connected = await self._try_connect(attempt)
|
||||
if not connected:
|
||||
continue # skip auth key generation until we're connected
|
||||
|
||||
if not self.auth_key:
|
||||
for attempt in retry_range(self._retries):
|
||||
if await self._try_gen_auth_key(attempt):
|
||||
break
|
||||
if not await self._try_gen_auth_key(attempt):
|
||||
continue # keep retrying until we have the auth key
|
||||
|
||||
break # all steps done, break retry loop
|
||||
else:
|
||||
if not connected:
|
||||
raise ConnectionError('Connection to Telegram failed %d time(s)', self._retries)
|
||||
|
||||
e = ConnectionError('auth_key generation failed %d time(s)', self._retries)
|
||||
await self._disconnect(error=e)
|
||||
raise e
|
||||
|
|
Loading…
Reference in New Issue
Block a user