https://github.com/python/cpython/commit/87d7436f0a344935269c4b889d1721bb8cccac8b commit: 87d7436f0a344935269c4b889d1721bb8cccac8b branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: kumaraditya303 <[email protected]> date: 2026-10-22T09:19:46Z summary:
[3.15] gh-159123: fix ResourceWarning flake in asyncio SSL handshake failure tests (GH-160209) (#160225) gh-159123: fix ResourceWarning flake in asyncio SSL handshake failure tests (GH-160209) (cherry picked from commit 5d887642d126bff378662fc6b145cc86b70207b0) Co-authored-by: Kumar Aditya <[email protected]> files: M Lib/test/test_asyncio/test_events.py diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index a3093d4dc8a748..2bd87a5bdb0413 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -1202,12 +1202,13 @@ def test_create_server_ssl_verify_failed(self): '(?i)certificate.verify.failed'): self.loop.run_until_complete(f_c) - # execute the loop to log the connection error - test_utils.run_briefly(self.loop) + # close connection: wait until the server-side transport of the + # failed handshake is closed as well, otherwise its socket may + # still be open when the loop is closed (gh-159123). + server.close() + self.loop.run_until_complete(server.wait_closed()) - # close connection self.assertIsNone(proto.transport) - server.close() @socket_helper.skip_unless_bind_unix_socket @unittest.skipIf(ssl is None, 'No ssl module') @@ -1232,12 +1233,13 @@ def test_create_unix_server_ssl_verify_failed(self): '(?i)certificate.verify.failed'): self.loop.run_until_complete(f_c) - # execute the loop to log the connection error - test_utils.run_briefly(self.loop) + # close connection: wait until the server-side transport of the + # failed handshake is closed as well, otherwise its socket may + # still be open when the loop is closed (gh-159123). + server.close() + self.loop.run_until_complete(server.wait_closed()) - # close connection self.assertIsNone(proto.transport) - server.close() @unittest.skipIf(ssl is None, 'No ssl module') def test_create_server_ssl_match_failed(self): @@ -1268,10 +1270,14 @@ def test_create_server_ssl_match_failed(self): with self.assertRaisesRegex(ssl.CertificateError, regex): self.loop.run_until_complete(f_c) - # close connection + # close connection: wait until the server-side transport of the + # failed handshake is closed as well, otherwise its socket may + # still be open when the loop is closed (gh-159123). + server.close() + self.loop.run_until_complete(server.wait_closed()) + # transport is None because TLS ALERT aborted the handshake self.assertIsNone(proto.transport) - server.close() @socket_helper.skip_unless_bind_unix_socket @unittest.skipIf(ssl is None, 'No ssl module') _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
