From cf35e2cf24ccdb67c7654a3790abf6229885c6f0 Mon Sep 17 00:00:00 2001 From: alemidev Date: Fri, 19 Nov 2021 16:30:08 +0100 Subject: [PATCH] safer disconnect sequence --- aiocraft/dispatcher.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aiocraft/dispatcher.py b/aiocraft/dispatcher.py index 66dc6bc..1117d2c 100644 --- a/aiocraft/dispatcher.py +++ b/aiocraft/dispatcher.py @@ -109,8 +109,11 @@ class Dispatcher: await asyncio.gather(self._writer, self._reader) self._logger.debug("Net workers stopped") if self._up: - if self._up.can_write_eof(): - self._up.write_eof() + if not self._up.is_closing() and self._up.can_write_eof(): + try: + self._up.write_eof() + except OSError as e: + self._logger.error("Could not write EOF : %s", str(e)) self._up.close() if block: await self._up.wait_closed()