From a070c2b52d89e331b039005b57b618a501481f6d Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Wed, 19 Jul 2023 08:42:58 -0700 Subject: [PATCH] Fix more issues with asyncio and timeouts [#962]. (cherry picked from commit 76eb9e81b33399dcc7e1309fdc0e8dae4b2ca372) --- dns/_asyncio_backend.py | 9 ++++++++- dns/quic/_asyncio.py | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dns/_asyncio_backend.py b/dns/_asyncio_backend.py index 64325351..94f751b1 100644 --- a/dns/_asyncio_backend.py +++ b/dns/_asyncio_backend.py @@ -37,7 +37,14 @@ class _DatagramProtocol: def connection_lost(self, exc): if self.recvfrom and not self.recvfrom.done(): - self.recvfrom.set_exception(exc) + if exc is None: + # EOF we triggered. Is there a better way to do this? + try: + raise EOFError + except EOFError as e: + self.recvfrom.set_exception(e) + else: + self.recvfrom.set_exception(exc) def close(self): self.transport.close() diff --git a/dns/quic/_asyncio.py b/dns/quic/_asyncio.py index cf1de8ec..e1c52339 100644 --- a/dns/quic/_asyncio.py +++ b/dns/quic/_asyncio.py @@ -188,6 +188,7 @@ class AsyncioQuicConnection(AsyncQuicConnection): self._connection.close() # sender might be blocked on this, so set it self._socket_created.set() + await self._socket.close() async with self._wake_timer: self._wake_timer.notify_all() try: -- 2.47.3