mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-04 12:10:21 +03:00
Acquire reconnect lock outside the reconnect function
This commit is contained in:
parent
d8376ee50d
commit
7da092894b
|
@ -248,7 +248,6 @@ class TelegramBareClient:
|
||||||
if new_dc is None:
|
if new_dc is None:
|
||||||
# Assume we are disconnected due to some error, so connect again
|
# Assume we are disconnected due to some error, so connect again
|
||||||
try:
|
try:
|
||||||
await self._reconnect_lock.acquire()
|
|
||||||
if self.is_connected():
|
if self.is_connected():
|
||||||
__log__.info('Reconnection aborted: already connected')
|
__log__.info('Reconnection aborted: already connected')
|
||||||
return True
|
return True
|
||||||
|
@ -258,8 +257,6 @@ class TelegramBareClient:
|
||||||
except ConnectionResetError as e:
|
except ConnectionResetError as e:
|
||||||
__log__.warning('Reconnection failed due to %s', e)
|
__log__.warning('Reconnection failed due to %s', e)
|
||||||
return False
|
return False
|
||||||
finally:
|
|
||||||
self._reconnect_lock.release()
|
|
||||||
else:
|
else:
|
||||||
# Since we're reconnecting possibly due to a UserMigrateError,
|
# Since we're reconnecting possibly due to a UserMigrateError,
|
||||||
# we need to first know the Data Centers we can connect to. Do
|
# we need to first know the Data Centers we can connect to. Do
|
||||||
|
@ -589,6 +586,7 @@ class TelegramBareClient:
|
||||||
if need_reconnect:
|
if need_reconnect:
|
||||||
__log__.info('Attempting reconnection from read loop')
|
__log__.info('Attempting reconnection from read loop')
|
||||||
need_reconnect = False
|
need_reconnect = False
|
||||||
|
with await self._reconnect_lock:
|
||||||
while self._user_connected and not await self._reconnect():
|
while self._user_connected and not await self._reconnect():
|
||||||
# Retry forever, this is instant messaging
|
# Retry forever, this is instant messaging
|
||||||
await asyncio.sleep(0.1, loop=self._loop)
|
await asyncio.sleep(0.1, loop=self._loop)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user