René's URL Explorer Experiment


Title: Data race on `ThreadHandle.ident` between `thread_shutdown` and `ThreadHandle_start` under free-threading · Issue #154937 · python/cpython · GitHub

Open Graph Title: Data race on `ThreadHandle.ident` between `thread_shutdown` and `ThreadHandle_start` under free-threading · Issue #154937 · python/cpython

X Title: Data race on `ThreadHandle.ident` between `thread_shutdown` and `ThreadHandle_start` under free-threading · Issue #154937 · python/cpython

Description: Bug report Bug description: On a free-threaded build, ThreadHandle.ident is written and read under two different locks. ThreadHandle_start sets self->ident while holding the handle's own mutex (self->mutex): cpython/Modules/_threadmodule...

Open Graph Description: Bug report Bug description: On a free-threaded build, ThreadHandle.ident is written and read under two different locks. ThreadHandle_start sets self->ident while holding the handle's own mutex (sel...

X Description: Bug report Bug description: On a free-threaded build, ThreadHandle.ident is written and read under two different locks. ThreadHandle_start sets self->ident while holding the handle's own mut...

Opengraph URL: https://github.com/python/cpython/issues/154937

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race on `ThreadHandle.ident` between `thread_shutdown` and `ThreadHandle_start` under free-threading","articleBody":"# Bug report\n\n### Bug description:\n\nOn a free-threaded  build, `ThreadHandle.ident` is written and read under two different locks.\n\n`ThreadHandle_start` sets `self->ident` while holding the handle's own mutex (`self->mutex`):\nhttps://github.com/python/cpython/blob/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc/Modules/_threadmodule.c#L483-L490\n\n`thread_shutdown` reads `cur->ident` while holding the runtime head lock (`HEAD_LOCK(&_PyRuntime)`):\nhttps://github.com/python/cpython/blob/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc/Modules/_threadmodule.c#L2408-L2422\n\nBecause the write is guarded by `self->mutex` and the read by `HEAD_LOCK`, the two do not exclude each other. \n\nhttps://github.com/python/cpython/blob/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc/Modules/_threadmodule.c#L1912-L1924\n\nThe comment explains the handle is added early to avoid missing a thread that finishes quickly, but that is exactly what exposes `ident` to the `HEAD_LOCK`-side reader in `thread_shutdown` before it is written under `self->mutex`.\n\nReproducer:\n```python\nimport _thread\nimport time\nfrom threading import Thread\n\ndef chain1_thread():\n    for _ in range(12000):\n        try:\n            _thread._shutdown()\n        except Exception:\n            pass\n\ndef chain2_thread():\n    for _ in range(12000):\n        try:\n            _thread.start_new_thread(lambda: None, ())\n        except Exception:\n            pass\n        time.sleep(0.0001)\n\nN_C1 = 1\nN_C2 = 8\nthreads  = [Thread(target=chain1_thread) for _ in range(N_C1)]\nthreads += [Thread(target=chain2_thread) for _ in range(N_C2)]\nfor t in threads: t.start()\nfor t in threads: t.join()\n```\n\nTSAN Report:\n```\nWARNING: ThreadSanitizer: data race (pid=657186)\n  Read of size 8 at 0x7fffb40a0570 by thread T1:\n    #0 thread_shutdown /cpython/./Modules/_threadmodule.c:2416:22 \n    #1 cfunction_vectorcall_NOARGS /cpython/Objects/methodobject.c:508:24 \n    #2 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:144:11 \n    #3 PyObject_Vectorcall /cpython/Objects/call.c:327:12 \n    #4 _Py_VectorCall_StackRefSteal /cpython/Python/ceval.c:726:11 \n    #5 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:4559:35 \n\n  Previous write of size 8 at 0x7fffb40a0570 by main thread:\n    #0 ThreadHandle_start /cpython/./Modules/_threadmodule.c:486:17 \n    #1 do_start_new_thread /cpython/./Modules/_threadmodule.c:1919:9 \n    #2 thread_PyThread_start_joinable_thread /cpython/./Modules/_threadmodule.c:2042:14 \n    #3 cfunction_call /cpython/Objects/methodobject.c:564:18  \n    #4 _PyObject_MakeTpCall /cpython/Objects/call.c:242:18 \n    #5 _PyObject_VectorcallTstate /cpython/./Include/internal/pycore_call.h:142:16 \n    #6 PyObject_Vectorcall /cpython/Objects/call.c:327:12 \n    #7 _Py_VectorCall_StackRefSteal /cpython/Python/ceval.c:726:11 \n    #8 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:3686:35 \n\nSUMMARY: ThreadSanitizer: data race /cpython/./Modules/_threadmodule.c:2416:22 in thread_shutdown\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-155085\n* gh-155123\n* gh-155124\n* gh-155125\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/Naserume","@type":"Person","name":"Naserume"},"datePublished":"2026-07-30T14:34:32Z","url":"https://github.com/python/cpython/issues/154937"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:1db9f52a-cabf-e227-d8f7-5f308bc79ad7
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB76A:399E4B:35DFCBA:477DA02:6B01F949
html-safe-nonce2d57ad71340e961c804a1933183206c4a717bc360b870218967712b4675320ab
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNzZBOjM5OUU0QjozNURGQ0JBOjQ3N0RBMDI6NkIwMUY5NDkiLCJ2aXNpdG9yX2lkIjoiODcwMDkwMDEzNzY1Mzg5MzQ0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacdacf03901b6d41a75142a917539074764858978fddc8701b873f39740fd74020
hovercard-subject-tagissue:5020840193
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/154937/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4e791077310a99d15ed6a1a037bfd173022af5ef3e4a3bac6d4be715bdf80d05/python/cpython/issues/154937
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4e791077310a99d15ed6a1a037bfd173022af5ef3e4a3bac6d4be715bdf80d05/python/cpython/issues/154937
og:image:altBug report Bug description: On a free-threaded build, ThreadHandle.ident is written and read under two different locks. ThreadHandle_start sets self->ident while holding the handle's own mutex (sel...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameNaserume
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/154937#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F154937
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F154937
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/154937
Reloadhttps://github.com/python/cpython/issues/154937
Reloadhttps://github.com/python/cpython/issues/154937
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154937
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154937
#155085https://github.com/python/cpython/pull/155085
Data race on ThreadHandle.ident between thread_shutdown and ThreadHandle_start under free-threadinghttps://github.com/python/cpython/issues/154937#top
#155085https://github.com/python/cpython/pull/155085
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/Naserume
Naserumehttps://github.com/Naserume
on Jul 30, 2026https://github.com/python/cpython/issues/154937#issue-5020840193
cpython/Modules/_threadmodule.chttps://github.com/python/cpython/blob/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc/Modules/_threadmodule.c#L483-L490
22a6c51https://github.com/python/cpython/commit/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc
cpython/Modules/_threadmodule.chttps://github.com/python/cpython/blob/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc/Modules/_threadmodule.c#L2408-L2422
22a6c51https://github.com/python/cpython/commit/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc
cpython/Modules/_threadmodule.chttps://github.com/python/cpython/blob/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc/Modules/_threadmodule.c#L1912-L1924
22a6c51https://github.com/python/cpython/commit/22a6c51c94a4fde986b8964f1d36d5ec3ac20dcc
gh-154937: Fix _thread._shutdown() racing with _thread.start_joinable_thread on ThreadHandle.ident #155085https://github.com/python/cpython/pull/155085
[3.15] gh-154937: Fix _thread._shutdown() racing with _thread.start_joinable_thread on ThreadHandle.ident (GH-155085) #155123https://github.com/python/cpython/pull/155123
[3.14] gh-154937: Fix _thread._shutdown() racing with _thread.start_joinable_thread on ThreadHandle.ident (GH-155085) #155124https://github.com/python/cpython/pull/155124
[3.13] gh-154937: Fix _thread._shutdown() racing with _thread.start_joinable_thread on ThreadHandle.ident (GH-155085) #155125https://github.com/python/cpython/pull/155125
Naserumehttps://github.com/Naserume
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Jul 30, 2026https://github.com/python/cpython/issues/154937#event-28726537653
aiskhttps://github.com/aisk
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
on Jul 30, 2026https://github.com/python/cpython/issues/154937#event-28730213275
aiskhttps://github.com/aisk
Threading issues 🧵https://github.com/orgs/python/projects/12
on Jul 30, 2026https://github.com/python/cpython/issues/154937#event-28730385260
https://github.com/LindaSummer
LindaSummerhttps://github.com/LindaSummer
on Jul 30, 2026https://github.com/python/cpython/issues/154937#issuecomment-5133224255
https://github.com/LindaSummer
LindaSummerhttps://github.com/LindaSummer
on Jul 31, 2026https://github.com/python/cpython/issues/154937#issuecomment-5137961441
kumaraditya303https://github.com/kumaraditya303
on Aug 3, 2026https://github.com/python/cpython/issues/154937#event-28896766415
gh-154937: Fix `_thread._shutdown()` racing with `_thread.start_joina…https://github.com/python/cpython/commit/a4095ee272f5e5082281a94a0856dde3c2f323f9
gh-154937https://github.com/python/cpython/issues/154937
a4095eehttps://github.com/python/cpython/commit/a4095ee272f5e5082281a94a0856dde3c2f323f9
kumaraditya303https://github.com/kumaraditya303
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#155085https://github.com/python/cpython/pull/155085
on Aug 3, 2026https://github.com/python/cpython/issues/154937#event-28896766594
github-project-automationhttps://github.com/apps/github-project-automation
Threading issues 🧵https://github.com/orgs/python/projects/12
on Aug 3, 2026https://github.com/python/cpython/issues/154937
Yhg1shttps://github.com/Yhg1s
on Aug 4, 2026https://github.com/python/cpython/issues/154937#event-28939287634
[3.13] gh-154937: Fix `_thread._shutdown()` racing with `_thread.star…https://github.com/python/cpython/commit/75344c0683eb2db6594fd5126b80a1c314b96d3c
gh-154937https://github.com/python/cpython/issues/154937
75344c0https://github.com/python/cpython/commit/75344c0683eb2db6594fd5126b80a1c314b96d3c
mbeijenhttps://github.com/mbeijen
on Aug 14, 2026https://github.com/python/cpython/issues/154937#event-29455498129
pythongh-154937: Fix `_thread._shutdown()` racing with `_thread.start…https://github.com/mbeijen/cpython/commit/f7872d105768e985e8bdb5ac4c66790db73c7dd2
pythongh-154937https://github.com/python/cpython/issues/154937
f7872d1https://github.com/mbeijen/cpython/commit/f7872d105768e985e8bdb5ac4c66790db73c7dd2
terryjreedyhttps://github.com/terryjreedy
on Sep 8, 2026https://github.com/python/cpython/issues/154937#event-30723351837
[3.14] gh-154937: Fix `_thread._shutdown()` racing with `_thread.star…https://github.com/python/cpython/commit/eef282bc0c1eb4e766f8a07e6afccdf09e230f4b
gh-154937https://github.com/python/cpython/issues/154937
eef282bhttps://github.com/python/cpython/commit/eef282bc0c1eb4e766f8a07e6afccdf09e230f4b
serhiy-storchakahttps://github.com/serhiy-storchaka
on Oct 10, 2026https://github.com/python/cpython/issues/154937#event-32936779648
[3.15] gh-154937: Fix `_thread._shutdown()` racing with `_thread.star…https://github.com/python/cpython/commit/dae3e8250f8013e83b2901df7a58e06e62f5e9d8
gh-154937https://github.com/python/cpython/issues/154937
dae3e82https://github.com/python/cpython/commit/dae3e8250f8013e83b2901df7a58e06e62f5e9d8
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/154937
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/154937
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Threading issues 🧵https://github.com/orgs/python/projects/12
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.