mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-02 19:20:09 +03:00
fix reconnect and retries
This commit is contained in:
parent
2a114917f1
commit
a1eacac3c3
|
@ -101,11 +101,11 @@ def retry_range(retries):
|
|||
not a zero or a positive integer value, the sequence will be
|
||||
infinite, otherwise it will end at `retries + 1`.
|
||||
"""
|
||||
yield 1
|
||||
|
||||
attempt = 0
|
||||
while attempt != retries:
|
||||
attempt += 1
|
||||
yield 1 + attempt
|
||||
attempt += 1
|
||||
|
||||
|
||||
async def _maybe_await(value):
|
||||
|
|
|
@ -217,6 +217,7 @@ class MTProtoSender:
|
|||
self._log.info('Connecting to %s...', self._connection)
|
||||
|
||||
connected = False
|
||||
attempt = 0
|
||||
for attempt in retry_range(self._retries):
|
||||
if not connected:
|
||||
connected = await self._try_connect(attempt)
|
||||
|
@ -357,6 +358,7 @@ class MTProtoSender:
|
|||
self._state.reset()
|
||||
|
||||
retries = self._retries if self._auto_reconnect else 0
|
||||
if retries:
|
||||
for attempt in retry_range(retries):
|
||||
try:
|
||||
await self._connect()
|
||||
|
@ -383,6 +385,9 @@ class MTProtoSender:
|
|||
else:
|
||||
self._log.error('Automatic reconnection failed %d time(s)', attempt)
|
||||
await self._disconnect(error=last_error.with_traceback(None))
|
||||
else:
|
||||
self._log.error('Automatic reconnection is False.')
|
||||
await self._disconnect(error=last_error.with_traceback(None))
|
||||
|
||||
def _start_reconnect(self, error):
|
||||
"""Starts a reconnection in the background."""
|
||||
|
|
Loading…
Reference in New Issue
Block a user