Skip to content

Commit

Permalink
Add a hard timeout on disconnect
Browse files Browse the repository at this point in the history
Closes #3917.
  • Loading branch information
Lonami committed Sep 21, 2022
1 parent 6d02a1c commit 1751631
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion telethon/network/connection/connection.py
Expand Up @@ -265,7 +265,12 @@ async def disconnect(self):
self._writer.close()
if sys.version_info >= (3, 7):
try:
await self._writer.wait_closed()
await asyncio.wait_for(self._writer.wait_closed(), timeout=10)
except asyncio.TimeoutError:
# See issue #3917. For some users, this line was hanging indefinitely.
# The hard timeout is not ideal (connection won't be properly closed),
# but the code will at least be able to procceed.
self._log.warning('Graceful disconnection timed out, forcibly ignoring cleanup')
except Exception as e:
# Disconnecting should never raise. Seen:
# * OSError: No route to host and
Expand Down

0 comments on commit 1751631

Please sign in to comment.