mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-05 22:23:15 +03: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:
parent
48a70308b5
commit
e24dd3ad75
|
@ -405,14 +405,17 @@ class TelegramBaseClient(abc.ABC):
|
||||||
except OSError:
|
except OSError:
|
||||||
print('Failed to connect')
|
print('Failed to connect')
|
||||||
"""
|
"""
|
||||||
await self._sender.connect(self._connection(
|
if not await self._sender.connect(self._connection(
|
||||||
self.session.server_address,
|
self.session.server_address,
|
||||||
self.session.port,
|
self.session.port,
|
||||||
self.session.dc_id,
|
self.session.dc_id,
|
||||||
loop=self._loop,
|
loop=self._loop,
|
||||||
loggers=self._log,
|
loggers=self._log,
|
||||||
proxy=self._proxy
|
proxy=self._proxy
|
||||||
))
|
)):
|
||||||
|
# We don't want to init or modify anything if we were already connected
|
||||||
|
return
|
||||||
|
|
||||||
self.session.auth_key = self._sender.auth_key
|
self.session.auth_key = self._sender.auth_key
|
||||||
self.session.save()
|
self.session.save()
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ class MTProtoSender:
|
||||||
self._auth_key_callback = auth_key_callback
|
self._auth_key_callback = auth_key_callback
|
||||||
self._update_callback = update_callback
|
self._update_callback = update_callback
|
||||||
self._auto_reconnect_callback = auto_reconnect_callback
|
self._auto_reconnect_callback = auto_reconnect_callback
|
||||||
|
self._connect_lock = asyncio.Lock(loop=loop)
|
||||||
|
|
||||||
# Whether the user has explicitly connected or disconnected.
|
# 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.
|
Connects to the specified given connection using the given auth key.
|
||||||
"""
|
"""
|
||||||
|
async with self._connect_lock:
|
||||||
if self._user_connected:
|
if self._user_connected:
|
||||||
self._log.info('User is already connected!')
|
self._log.info('User is already connected!')
|
||||||
return
|
return False
|
||||||
|
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
await self._connect()
|
await self._connect()
|
||||||
self._user_connected = True
|
self._user_connected = True
|
||||||
|
return True
|
||||||
|
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
return self._user_connected
|
return self._user_connected
|
||||||
|
|
Loading…
Reference in New Issue
Block a user