From 22ffee21aa94553d65010b540dac7dd8258fe5c3 Mon Sep 17 00:00:00 2001 From: glaziermag Date: Fri, 13 Nov 2026 08:31:18 -0800 Subject: [PATCH] tls: close the TLS socket in _TLSAutomaton.destroy() Automaton.destroy() does not close the TCP socket of a TLS automaton. When test_tls_client() stops the server after a client failure (the invalid ServerKeyExchange signature test from #5248), the server can stop before close_session runs; the accepted socket is then garbage collected during a later test, and its ResourceWarning in the captured stderr fails that test. AI-Assisted: yes (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 --- scapy/layers/tls/automaton.py | 6 ++++++ test/scapy/layers/tls/tlsclientserver.uts | 1 + 2 files changed, 7 insertions(+) diff --git a/scapy/layers/tls/automaton.py b/scapy/layers/tls/automaton.py index 647ad5280b4..445a3386ebf 100644 --- a/scapy/layers/tls/automaton.py +++ b/scapy/layers/tls/automaton.py @@ -69,6 +69,12 @@ def __init__(self, *args, **kwargs): kwargs["recvsock"] = lambda *args, **kwargs: None super(_TLSAutomaton, self).__init__(*args, **kwargs) + def destroy(self, force=False): + # Automaton.destroy() does not know about the TLS socket + if getattr(self, "socket", None) is not None: + self.socket.close() + super(_TLSAutomaton, self).destroy(force=force) + def parse_args(self, mycert=None, mykey=None, **kargs): self.verbose = kargs.pop("verbose", True) diff --git a/test/scapy/layers/tls/tlsclientserver.uts b/test/scapy/layers/tls/tlsclientserver.uts index 18b7c4fa7e9..0349541bd7a 100644 --- a/test/scapy/layers/tls/tlsclientserver.uts +++ b/test/scapy/layers/tls/tlsclientserver.uts @@ -348,6 +348,7 @@ def test_tls_client(suite, version, curve=None, cookie=False, client_auth=False, print("Server stopped. Destroying server...") atmtsrv.destroy(force=True) print("Server destroyed.") + assert atmtsrv.socket is None or atmtsrv.socket.fileno() == -1 # re-raise if client failed. if final_reason: raise ValueError(final_reason.atmt_origfunc)