Skip to content

Commit ff74fd7

Browse files
committed
gh-108342: Break ref cycle in test_ssl preauth
In preauth tests of test_ssl, explicitly break reference cycles invoving SingleConnectionTestServerThread to make sure that the thread is deleted. Otherwise, the test marks the environment as altered because the threading module sees a "dangling thread" (SingleConnectionTestServerThread). This test leak was introduced by the test added for the fix of issue gh-108310.
1 parent 2135bcd commit ff74fd7

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

Lib/test/test_ssl.py

+35-18
Original file line numberDiff line numberDiff line change
@@ -4734,8 +4734,13 @@ def non_linux_skip_if_other_okay_error(self, err):
47344734
# we're specifically trying to test. The way this test is written
47354735
# is known to work on Linux. We'll skip it anywhere else that it
47364736
# does not present as doing so.
4737-
self.skipTest(f"Could not recreate conditions on {sys.platform}:"
4738-
f" {err=}")
4737+
try:
4738+
self.skipTest(f"Could not recreate conditions on {sys.platform}:"
4739+
f" {err=}")
4740+
finally:
4741+
# gh-108342: Explicitly break the reference cycle
4742+
err = None
4743+
47394744
# If maintaining this conditional winds up being a problem.
47404745
# just turn this into an unconditional skip anything but Linux.
47414746
# The important thing is that our CI has the logic covered.
@@ -4767,15 +4772,22 @@ def call_after_accept(unused):
47674772

47684773
ready_for_server_wrap_socket.set()
47694774
server.join()
4775+
47704776
wrap_error = server.wrap_error
4771-
self.assertEqual(b"", server.received_data)
4772-
self.assertIsInstance(wrap_error, OSError) # All platforms.
4773-
self.non_linux_skip_if_other_okay_error(wrap_error)
4774-
self.assertIsInstance(wrap_error, ssl.SSLError)
4775-
self.assertIn("before TLS handshake with data", wrap_error.args[1])
4776-
self.assertIn("before TLS handshake with data", wrap_error.reason)
4777-
self.assertNotEqual(0, wrap_error.args[0])
4778-
self.assertIsNone(wrap_error.library, msg="attr must exist")
4777+
server.wrap_error = None
4778+
try:
4779+
self.assertEqual(b"", server.received_data)
4780+
self.assertIsInstance(wrap_error, OSError) # All platforms.
4781+
self.non_linux_skip_if_other_okay_error(wrap_error)
4782+
self.assertIsInstance(wrap_error, ssl.SSLError)
4783+
self.assertIn("before TLS handshake with data", wrap_error.args[1])
4784+
self.assertIn("before TLS handshake with data", wrap_error.reason)
4785+
self.assertNotEqual(0, wrap_error.args[0])
4786+
self.assertIsNone(wrap_error.library, msg="attr must exist")
4787+
finally:
4788+
# gh-108342: Explicitly break the reference cycle
4789+
wrap_error = None
4790+
server = None
47794791

47804792
def test_preauth_data_to_tls_client(self):
47814793
client_can_continue_with_wrap_socket = threading.Event()
@@ -4815,14 +4827,19 @@ def call_after_accept(conn_to_client):
48154827
tls_client.close()
48164828

48174829
server.join()
4818-
self.assertEqual(b"", received_data)
4819-
self.assertIsInstance(wrap_error, OSError) # All platforms.
4820-
self.non_linux_skip_if_other_okay_error(wrap_error)
4821-
self.assertIsInstance(wrap_error, ssl.SSLError)
4822-
self.assertIn("before TLS handshake with data", wrap_error.args[1])
4823-
self.assertIn("before TLS handshake with data", wrap_error.reason)
4824-
self.assertNotEqual(0, wrap_error.args[0])
4825-
self.assertIsNone(wrap_error.library, msg="attr must exist")
4830+
try:
4831+
self.assertEqual(b"", received_data)
4832+
self.assertIsInstance(wrap_error, OSError) # All platforms.
4833+
self.non_linux_skip_if_other_okay_error(wrap_error)
4834+
self.assertIsInstance(wrap_error, ssl.SSLError)
4835+
self.assertIn("before TLS handshake with data", wrap_error.args[1])
4836+
self.assertIn("before TLS handshake with data", wrap_error.reason)
4837+
self.assertNotEqual(0, wrap_error.args[0])
4838+
self.assertIsNone(wrap_error.library, msg="attr must exist")
4839+
finally:
4840+
# gh-108342: Explicitly break the reference cycle
4841+
wrap_error = None
4842+
server = None
48264843

48274844
def test_https_client_non_tls_response_ignored(self):
48284845

0 commit comments

Comments
 (0)