mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-21 17:06:36 +03:00
Exit receive loop on IOError or unhandled exceptions
May help with #4088.
This commit is contained in:
parent
03ff996ace
commit
ccf67d0f4f
|
@ -253,7 +253,8 @@ class Connection(abc.ABC):
|
|||
Disconnects from the server, and clears
|
||||
pending outgoing and incoming messages.
|
||||
"""
|
||||
self._connected = False
|
||||
if not self._connected:
|
||||
return
|
||||
|
||||
await helpers._cancel(
|
||||
self._log,
|
||||
|
@ -278,6 +279,8 @@ class Connection(abc.ABC):
|
|||
# * ConnectionResetError
|
||||
self._log.info('%s during disconnect: %s', type(e), e)
|
||||
|
||||
self._connected = False
|
||||
|
||||
def send(self, data):
|
||||
"""
|
||||
Sends a packet of data through this connection mode.
|
||||
|
@ -333,6 +336,7 @@ class Connection(abc.ABC):
|
|||
except (IOError, asyncio.IncompleteReadError) as e:
|
||||
self._log.warning('Server closed the connection: %s', e)
|
||||
await self._recv_queue.put((None, e))
|
||||
await self.disconnect()
|
||||
except InvalidChecksumError as e:
|
||||
self._log.warning('Server response had invalid checksum: %s', e)
|
||||
await self._recv_queue.put((None, e))
|
||||
|
@ -342,6 +346,7 @@ class Connection(abc.ABC):
|
|||
except Exception as e:
|
||||
self._log.exception('Unexpected exception in the receive loop')
|
||||
await self._recv_queue.put((None, e))
|
||||
await self.disconnect()
|
||||
else:
|
||||
await self._recv_queue.put((data, None))
|
||||
except asyncio.CancelledError:
|
||||
|
|
Loading…
Reference in New Issue
Block a user