mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Prevent double-connect causing double-reads later
Which leads to "RuntimeError: readexactly() called while another coroutine is already waiting for incoming data" being raised, and causing everything to break or halt.
This commit is contained in:
@@ -54,6 +54,7 @@ class MTProtoSender:
|
||||
self._auth_key_callback = auth_key_callback
|
||||
self._update_callback = update_callback
|
||||
self._auto_reconnect_callback = auto_reconnect_callback
|
||||
self._connect_lock = asyncio.Lock(loop=loop)
|
||||
|
||||
# Whether the user has explicitly connected or disconnected.
|
||||
#
|
||||
@@ -114,13 +115,15 @@ class MTProtoSender:
|
||||
"""
|
||||
Connects to the specified given connection using the given auth key.
|
||||
"""
|
||||
if self._user_connected:
|
||||
self._log.info('User is already connected!')
|
||||
return
|
||||
async with self._connect_lock:
|
||||
if self._user_connected:
|
||||
self._log.info('User is already connected!')
|
||||
return False
|
||||
|
||||
self._connection = connection
|
||||
await self._connect()
|
||||
self._user_connected = True
|
||||
self._connection = connection
|
||||
await self._connect()
|
||||
self._user_connected = True
|
||||
return True
|
||||
|
||||
def is_connected(self):
|
||||
return self._user_connected
|
||||
|
Reference in New Issue
Block a user