Skip to content

gh-136870: fix race in PyThreadState_Clear on sys_tracing_threads #136951

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

Merged
merged 1 commit into from
Jul 21, 2025

Conversation

kumaraditya303
Copy link
Contributor

@kumaraditya303 kumaraditya303 commented Jul 21, 2025

In free-threading multiple threads can be cleared concurrently as such the modifications on sys_tracing_threads should be done while holding the profile lock otherwise it can race with other threads setting up profiling.

@ZeroIntensity
Copy link
Member

No news entry? This is fixing public APIs.

@kumaraditya303
Copy link
Contributor Author

kumaraditya303 commented Jul 21, 2025

No news entry? This is fixing public APIs.

I don't think news entries for data race fixes like this one are useful for user, we haven't been adding news for most of these changes unless it's a large change like fixing all races of a module.

@kumaraditya303 kumaraditya303 merged commit f183996 into python:main Jul 21, 2025
52 checks passed
@miss-islington-app
Copy link

Thanks @kumaraditya303 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 21, 2025
…ng_threads` (pythonGH-136951)

In free-threading, multiple threads can be cleared concurrently as such the modifications on `sys_tracing_threads` should be done while holding the profile lock, otherwise it can race with other threads setting up profiling.
(cherry picked from commit f183996eb77fd2d5662c62667298c292c943ebf5)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Jul 21, 2025

GH-136953 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jul 21, 2025
@kumaraditya303 kumaraditya303 deleted the ts-clear-monitoring branch July 21, 2025 20:39
kumaraditya303 added a commit that referenced this pull request Jul 21, 2025
…ing_threads` (GH-136951) (#136953)

gh-136870: fix data race in `PyThreadState_Clear` on `sys_tracing_threads` (GH-136951)

In free-threading, multiple threads can be cleared concurrently as such the modifications on `sys_tracing_threads` should be done while holding the profile lock, otherwise it can race with other threads setting up profiling.
(cherry picked from commit f183996)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants