From 9a8ef9b0a377faae11a8a07af23978c4cd573fcb Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 11 Jun 2026 13:49:45 +0200 Subject: [PATCH] test: SOCKS5 proxy: expect that connection may be reset during handshake The client (e.g. `bitcoind`) may open a connection to the proxy and close it in the middle of the SOCKS5 handshake if it is restarted for example. Log these as debug messages instead of full blown Python exception error messages with backtraces. --- test/functional/test_framework/socks5.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/functional/test_framework/socks5.py b/test/functional/test_framework/socks5.py index a794dc08b3b..f7a1aabddd4 100644 --- a/test/functional/test_framework/socks5.py +++ b/test/functional/test_framework/socks5.py @@ -138,7 +138,12 @@ class Socks5Connection(): def handle(self): """Handle socks5 request according to RFC1928.""" + log_exception_prefix = "Socks5Connection.handle(): " try: + log_exception_prefix = ("Socks5Connection.handle(" + f"client={format_sock(self.conn, local=False)}, " + f"proxy={format_sock(self.conn, local=True)}): ") + # Verify socks version ver = recvall(self.conn, 1)[0] if ver != 0x05: @@ -212,9 +217,12 @@ class Socks5Connection(): else: logger.debug(f"Can't serve the connection to {requested_to}: no destinations factory") - # Fall through to disconnect + # Disconnect happens in the "finally" block below. + + except (BrokenPipeError, ConnectionResetError) as e: + logger.debug(f"{log_exception_prefix}abnormal connection close: {str(e)}") except Exception as e: - logger.exception(f"socks5 request handling failed (running {self.serv.is_running()})") + logger.exception(f"{log_exception_prefix}exception: {str(e)} (running {self.serv.is_running()})") if self.serv.is_running(): self.serv.queue.put(e) finally: