From 3a1c0dba8011de7b82ef35aaa5898caf7bb6389e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20K=C4=99pie=C5=84?= Date: Tue, 18 Mar 2025 16:28:18 +0100 Subject: [PATCH] Handle connection resets during reading A TCP peer may reset the connection at any point, but asyncserver.py currently only handles connection resets when it is sending data to the client. Handle connection resets during reading in the same way. (cherry picked from commit 748ed4259b66e4b33acf1d2584dc92da00d31aec) --- bin/tests/system/isctest/asyncserver.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/tests/system/isctest/asyncserver.py b/bin/tests/system/isctest/asyncserver.py index 7a3285402c..6e62f483a6 100644 --- a/bin/tests/system/isctest/asyncserver.py +++ b/bin/tests/system/isctest/asyncserver.py @@ -542,10 +542,14 @@ class AsyncDnsServer(AsyncServer): peer = Peer(peer_info[0], peer_info[1]) for _ in range(0, 1): - wire = await self._read_tcp_query(reader) - if not wire: - break - await self._send_tcp_response(writer, peer, wire) + try: + wire = await self._read_tcp_query(reader) + if not wire: + break + await self._send_tcp_response(writer, peer, wire) + except ConnectionResetError: + logging.error("TCP connection from %s reset by peer", peer) + return writer.close() await writer.wait_closed() @@ -587,11 +591,7 @@ class AsyncDnsServer(AsyncServer): responses = self._handle_query(wire, peer, DnsProtocol.TCP) async for response in responses: writer.write(response) - try: - await writer.drain() - except ConnectionResetError: - logging.error("TCP connection from %s reset by peer", peer) - return + await writer.drain() def _log_query(self, qctx: QueryContext, peer: Peer, protocol: DnsProtocol) -> None: logging.info(