Skip to content

Commit 8687101

Browse files
authored
bpo-31323: Fix reference leak in test_ssl (#3263)
Store exceptions as string rather than object to prevent reference cycles which cause leaking dangling threads.
1 parent e8a533f commit 8687101

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/test/test_ssl.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,11 @@ def wrap_conn(self):
18891889
# XXX Various errors can have happened here, for example
18901890
# a mismatching protocol version, an invalid certificate,
18911891
# or a low-level bug. This should be made more discriminating.
1892-
self.server.conn_errors.append(e)
1892+
#
1893+
# bpo-31323: Store the exception as string to prevent
1894+
# a reference leak: server -> conn_errors -> exception
1895+
# -> traceback -> self (ConnectionHandler) -> server
1896+
self.server.conn_errors.append(str(e))
18931897
if self.server.chatty:
18941898
handle_error("\n server: bad connection attempt from " + repr(self.addr) + ":\n")
18951899
self.running = False
@@ -3097,7 +3101,7 @@ def test_default_ciphers(self):
30973101
with context.wrap_socket(socket.socket()) as s:
30983102
with self.assertRaises(OSError):
30993103
s.connect((HOST, server.port))
3100-
self.assertIn("no shared cipher", str(server.conn_errors[0]))
3104+
self.assertIn("no shared cipher", server.conn_errors[0])
31013105

31023106
def test_version_basic(self):
31033107
"""

0 commit comments

Comments
 (0)