mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-11-13 12:30:40 +00:00
Cancel tasks on reconnect instead of awaiting them
This prevents us from locking forever on any task that doesn't rely on cancellation tokens, in this case, Connection.recv()'s _recv_queue.get() would never complete after the server closed the connection. Additionally, working with cancellation tokens in asyncio is somewhat annoying to do. Last but not least removing the Connection._disconnected future avoids the need to use its state (if an exception was set it should be retrieved) to prevent asyncio from complaining, which it was before.
This commit is contained in:
@@ -279,11 +279,11 @@ class MTProtoSender:
|
||||
__log__.debug('Closing current connection...')
|
||||
self._connection.disconnect()
|
||||
|
||||
__log__.debug('Awaiting for the send loop before reconnecting...')
|
||||
await self._send_loop_handle
|
||||
__log__.debug('Cancelling the send loop...')
|
||||
self._send_loop_handle.cancel()
|
||||
|
||||
__log__.debug('Awaiting for the receive loop before reconnecting...')
|
||||
await self._recv_loop_handle
|
||||
__log__.debug('Cancelling the receive loop...')
|
||||
self._recv_loop_handle.cancel()
|
||||
|
||||
self._reconnecting = False
|
||||
|
||||
@@ -334,8 +334,7 @@ class MTProtoSender:
|
||||
# This means that while it's not empty we can wait for
|
||||
# more messages to be added to the send queue.
|
||||
try:
|
||||
batch, data = await self._send_queue.get(
|
||||
self._connection.disconnected)
|
||||
batch, data = await self._send_queue.get()
|
||||
except asyncio.CancelledError:
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user