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.
This commit is contained in:
Vasil Dimov
2026-06-11 13:49:45 +02:00
parent eb3208364a
commit 9a8ef9b0a3

View File

@@ -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: