Skip to content

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

Closed
@vstinner

Description

@vstinner

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

Activity

colesbury

colesbury commented on Nov 7, 2024

@colesbury
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

vstinner commented on Apr 2, 2025

@vstinner
MemberAuthor
kumaraditya303

kumaraditya303 commented on Apr 18, 2025

@kumaraditya303
Contributor

Should be fixed now as warnings is thread safe now.

graingert

graingert commented on Apr 18, 2025

@graingert
Contributor

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

added a commit that references this issue on Apr 18, 2025

pythongh-126483: disable warnings filters mutation in concurrent test…

6a0d82f
added
3.13bugs and security fixes
3.14bugs and security fixes
on Apr 18, 2025
graingert

graingert commented on Apr 18, 2025

@graingert
Contributor

this also needs fixing on 3.13

added a commit that references this issue on Jun 4, 2025

gh-126483: disable warnings filters mutation in concurrent test (GH-1…

40c8be0

8 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixestestsTests in the Lib/test dirtopic-free-threading

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      [FreeThreading] test_ssl fails with env_changed: warnings.filters was modified by test_ssl · Issue #126483 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant