Skip to content

Commit ae2e795

Browse files
miss-islingtongraingertcolesbury
authored
[3.13] gh-126483: disable warnings filters mutation in concurrent test (GH-132694) (GH-135132)
The `test_ssl_in_multiple_threads` test failed because `test_check_hostname_idn()` modified the global warnings filters via `warnings_helper.check_no_resource_warning()`. Disable the warnings check in the multi-threaded test because `warnings_helper` isn't thread-safe in 3.13 or earlier. (cherry picked from commit 40c8be0) Co-authored-by: Thomas Grainger <tagrain@gmail.com> * Fix for 3.13 --------- Co-authored-by: Thomas Grainger <tagrain@gmail.com> Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent 70c7aad commit ae2e795

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

Lib/test/test_ssl.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import platform
3232
import sysconfig
3333
import functools
34+
from contextlib import nullcontext
3435
try:
3536
import ctypes
3637
except ImportError:
@@ -2879,7 +2880,10 @@ def test_ssl_in_multiple_threads(self):
28792880
self.test_alpn_protocols,
28802881
self.test_getpeercert,
28812882
self.test_crl_check,
2882-
self.test_check_hostname_idn,
2883+
functools.partial(
2884+
self.test_check_hostname_idn,
2885+
warnings_filters=False, # gh-126483
2886+
),
28832887
self.test_wrong_cert_tls12,
28842888
self.test_wrong_cert_tls13,
28852889
):
@@ -3125,7 +3129,7 @@ def test_dual_rsa_ecc(self):
31253129
cipher = s.cipher()[0].split('-')
31263130
self.assertTrue(cipher[:2], ('ECDHE', 'ECDSA'))
31273131

3128-
def test_check_hostname_idn(self):
3132+
def test_check_hostname_idn(self, warnings_filters=True):
31293133
if support.verbose:
31303134
sys.stdout.write("\n")
31313135

@@ -3180,16 +3184,30 @@ def test_check_hostname_idn(self):
31803184
server_hostname="python.example.org") as s:
31813185
with self.assertRaises(ssl.CertificateError):
31823186
s.connect((HOST, server.port))
3183-
with ThreadedEchoServer(context=server_context, chatty=True) as server:
3184-
with warnings_helper.check_no_resource_warning(self):
3185-
with self.assertRaises(UnicodeError):
3186-
context.wrap_socket(socket.socket(),
3187-
server_hostname='.pythontest.net')
3188-
with ThreadedEchoServer(context=server_context, chatty=True) as server:
3189-
with warnings_helper.check_no_resource_warning(self):
3190-
with self.assertRaises(UnicodeDecodeError):
3191-
context.wrap_socket(socket.socket(),
3192-
server_hostname=b'k\xf6nig.idn.pythontest.net')
3187+
with (
3188+
ThreadedEchoServer(context=server_context, chatty=True) as server,
3189+
(
3190+
warnings_helper.check_no_resource_warning(self)
3191+
if warnings_filters
3192+
else nullcontext()
3193+
),
3194+
self.assertRaises(UnicodeError),
3195+
):
3196+
context.wrap_socket(socket.socket(), server_hostname='.pythontest.net')
3197+
3198+
with (
3199+
ThreadedEchoServer(context=server_context, chatty=True) as server,
3200+
(
3201+
warnings_helper.check_no_resource_warning(self)
3202+
if warnings_filters
3203+
else nullcontext()
3204+
),
3205+
self.assertRaises(UnicodeDecodeError),
3206+
):
3207+
context.wrap_socket(
3208+
socket.socket(),
3209+
server_hostname=b'k\xf6nig.idn.pythontest.net',
3210+
)
31933211

31943212
def test_wrong_cert_tls12(self):
31953213
"""Connecting when the server rejects the client's certificate

0 commit comments

Comments
 (0)