Skip to content

[FreeThreading] test_ssl fails with env_changed: warnings.filters was modified by test_ssl #126483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vstinner opened this issue Nov 6, 2024 · 5 comments
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes tests Tests in the Lib/test dir topic-free-threading

Comments

@vstinner
Copy link
Member

vstinner commented Nov 6, 2024

On a Free Threaded build, test_ssl fails with:

$ ./python -m test test_ssl --fail-env-changed -m test_ssl_in_multiple_threads 
(...)
Warning -- warnings.filters was modified by test_ssl
Warning --   Before: (2199023321584, [], [])
Warning --   After:  (2199997062288, [('always', None, <class 'ResourceWarning'>, None, 0)], [('always', None, <class 'ResourceWarning'>, None, 0)]) 
test_ssl failed (env changed)
(...)
Result: ENV CHANGED

The problem comes from test_check_hostname_idn() which uses warnings_helper.check_no_resource_warning() (changes warnings filters).

Linked PRs

@vstinner vstinner added tests Tests in the Lib/test dir topic-free-threading labels Nov 6, 2024
@colesbury
Copy link
Contributor

To add to your description: check_no_resource_warning() uses warnings.filterwarnings and warnings.catch_warnings, which are not thread-safe in Python (even with the GIL).

So it's not safe to run test_check_hostname_idn from multiple threads concurrently like test_ssl_in_multiple_threads is doing.

@vstinner
Copy link
Member Author

vstinner commented Apr 2, 2025

cc @nascheme

@kumaraditya303
Copy link
Contributor

Should be fixed now as warnings is thread safe now.

@graingert
Copy link
Contributor

graingert commented Apr 18, 2025

It's safe (and only by default) on the free threaded builds, but not on the regular builds

@graingert graingert reopened this Apr 18, 2025
graingert added a commit to graingert/cpython that referenced this issue Apr 18, 2025
…_check_hostname_idn use by test_ssl_in_multiple_threads
@graingert graingert added 3.13 bugs and security fixes 3.14 bugs and security fixes labels Apr 18, 2025
@graingert
Copy link
Contributor

this also needs fixing on 3.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 bugs and security fixes tests Tests in the Lib/test dir topic-free-threading
Projects
None yet
Development

No branches or pull requests

4 participants