Add a hard timeout on disconnect

Closes #3917.
This commit is contained in:
Lonami Exo 2022-09-21 10:58:35 +02:00
parent 6d02a1c6ff
commit 17516318e6

View File

@ -265,7 +265,12 @@ class Connection(abc.ABC):
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