Skip to content

Commit

Permalink
Fix asyncio.CancelledError was being swallowed by inner except
Browse files Browse the repository at this point in the history
Closes #4104.
  • Loading branch information
Lonami committed May 8, 2023
1 parent 980f8b3 commit 6a7a981
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions telethon/network/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ async def disconnect(self):
if not self._connected:
return

self._connected = False

await helpers._cancel(
self._log,
send_task=self._send_task,
Expand All @@ -279,8 +281,6 @@ async def disconnect(self):
# * 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.
Expand Down Expand Up @@ -333,6 +333,8 @@ async def _recv_loop(self):
while self._connected:
try:
data = await self._recv()
except asyncio.CancelledError:
break
except (IOError, asyncio.IncompleteReadError) as e:
self._log.warning('Server closed the connection: %s', e)
await self._recv_queue.put((None, e))
Expand All @@ -349,8 +351,6 @@ async def _recv_loop(self):
await self.disconnect()
else:
await self._recv_queue.put((data, None))
except asyncio.CancelledError:
pass
finally:
await self.disconnect()

Expand Down

0 comments on commit 6a7a981

Please sign in to comment.