René's URL Explorer Experiment


Title: Free-threading race betwen two Py_SETREF · Issue #161714 · python/cpython · GitHub

Open Graph Title: Free-threading race betwen two Py_SETREF · Issue #161714 · python/cpython

X Title: Free-threading race betwen two Py_SETREF · Issue #161714 · python/cpython

Description: Bug report This can be triggered with existing Python objects that use Py_SETREF or Py_XSETREF such as Exceptions (although slightly contrived): import threading e = Exception() def worker(): for _ in range(1_000_000): e.__init__(1) thre...

Open Graph Description: Bug report This can be triggered with existing Python objects that use Py_SETREF or Py_XSETREF such as Exceptions (although slightly contrived): import threading e = Exception() def worker(): for _...

X Description: Bug report This can be triggered with existing Python objects that use Py_SETREF or Py_XSETREF such as Exceptions (although slightly contrived): import threading e = Exception() def worker(): for _...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Free-threading race betwen two Py_SETREF","articleBody":"### Bug report\n\nThis can be triggered with existing Python objects that use `Py_SETREF` or `Py_XSETREF` such as Exceptions (although slightly contrived):\n```python\nimport threading\n\ne = Exception()\n\ndef worker():\n    for _ in range(1_000_000):\n        e.__init__(1)\n\nthreads = [threading.Thread(target=worker) for _ in range(2)]\nfor t in threads:\n    t.start()\nfor t in threads:\n    t.join()\n```\n\nGives on a 3.16 free-threaded debug build:\n```\n../cpython/Include/refcount.h:617: _Py_NegativeRefcount: Assertion failed: object has negative ref count\nEnable tracemalloc to get the memory block allocation traceback\n\nobject address  : 0x2000204c3b0\nobject refcount : 0\nobject type     : 0x5623737ad5c8\nobject type name: tuple\nobject repr     : \u003crefcnt 0 at 0x2000204c3b0>\n\nFatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed\nPython runtime state: initialized\n\nStack (most recent call first):\n  File \"/\u003chome>/projects/python/setref_bug.py\", line 8 in worker\n  File \"/\u003chome>/projects/python/cpython/Lib/threading.py\", line 1161 in run\n  File \"/\u003chome>/projects/python/cpython/Lib/threading.py\", line 1219 in _bootstrap_inner\n  File \"/\u003chome>/projects/python/cpython/Lib/threading.py\", line 1181 in _bootstrap\n[1]    397225 abort (core dumped)  ./build/python setref_bug.py\n```\n\nThis arrives because `Py_SETREF` copies the ref and stores a new new one as two separate non-atomic steps. So two threads can do:\n\n```\nT1: old = *slot\nT2: old = *slot      // same object as T1\nT1: *slot = a\nT2: *slot = b        // a's reference is lost, so a leaks\nT1: Py_XDECREF(old)\nT2: Py_XDECREF(old)  // the slot's one reference to old is dropped twice\n```\n\nI ran into this trying to build a cache which swapped an old value for a new value with `Py_SETREF` and finding it sometimes resulted in a double free when two threads swapped the value simultaneously (And ended up thinking they had the last reference).\n\n### CPython versions tested on:\n\n3.16, CPython main branch\n\n### Operating systems tested on:\n\nLinux","author":{"url":"https://github.com/cmaloney","@type":"Person","name":"cmaloney"},"datePublished":"2026-11-09T23:34:22Z","url":"https://github.com/python/cpython/issues/161714"}

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:78a7bae0-934a-8e00-7f48-6b233ab01a82
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAFFE:16AB79:3C9FA06:4D08295:6B020AE4
html-safe-noncea04e29ebdaffbad191e27f0c83c67833aac464a9982ec4034d0cdb2b3312388d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkZFOjE2QUI3OTozQzlGQTA2OjREMDgyOTU6NkIwMjBBRTQiLCJ2aXNpdG9yX2lkIjoiODI3OTU0MjMwMjM2MDM0MTIyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacbcbd5dbd69495a94aed2f79fd8b3f2e3c71ad1b9a3d1033559f2ed50039c4d2c
hovercard-subject-tagissue:6296878675
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/161714/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d896d687fcd17ddd3035e5ae00abb44f97006658fc87af8a86057ddb572e8ee5/python/cpython/issues/161714
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d896d687fcd17ddd3035e5ae00abb44f97006658fc87af8a86057ddb572e8ee5/python/cpython/issues/161714
og:image:altBug report This can be triggered with existing Python objects that use Py_SETREF or Py_XSETREF such as Exceptions (although slightly contrived): import threading e = Exception() def worker(): for _...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecmaloney
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/161714#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F161714
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%2F161714
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/161714
Reloadhttps://github.com/python/cpython/issues/161714
Reloadhttps://github.com/python/cpython/issues/161714
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/161714
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/161714
Free-threading race betwen two Py_SETREFhttps://github.com/python/cpython/issues/161714#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%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/cmaloney
cmaloneyhttps://github.com/cmaloney
on Nov 9, 2026https://github.com/python/cpython/issues/161714#issue-6296878675
cmaloneyhttps://github.com/cmaloney
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
on Nov 9, 2026https://github.com/python/cpython/issues/161714#event-35626075913
https://github.com/colesbury
colesburyhttps://github.com/colesbury
on Nov 9, 2026https://github.com/python/cpython/issues/161714#issuecomment-6754540274
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Nov 10, 2026https://github.com/python/cpython/issues/161714#issuecomment-6755668618
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Nov 13, 2026https://github.com/python/cpython/issues/161714#issuecomment-6840900162
issue 1https://github.com/python/cpython/issues/121647
issue 2https://github.com/python/cpython/issues/157649
strict aliasing issuehttps://github.com/python/cpython/issues/161185
https://github.com/python/cpython/pull/161793/changeshttps://github.com/python/cpython/pull/161793/changes
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Nov 15, 2026https://github.com/python/cpython/issues/161714#issuecomment-6888356327
cpython/Python/_warnings.chttps://github.com/python/cpython/blob/60eca2df18fcd47d71ab136e460efabbc2f4a044/Python/_warnings.c#L343-L363
60eca2dhttps://github.com/python/cpython/commit/60eca2df18fcd47d71ab136e460efabbc2f4a044
cmaloneyhttps://github.com/cmaloney
on Nov 15, 2026https://github.com/python/cpython/issues/161714#event-36168911405
fixup! pythongh-161714: Add internal Py_REF_ATOMIC_SWAP() and Py_REF_…https://github.com/cmaloney/cpython/commit/ccbce6de3e0774457cf4bdbbc596238c77043a51
pythongh-161714https://github.com/python/cpython/issues/161714
ccbce6dhttps://github.com/cmaloney/cpython/commit/ccbce6de3e0774457cf4bdbbc596238c77043a51
fixup! pythongh-161714: Use Py_REF_ATOMIC_SWAP() and Py_REF_ATOMIC_INC()https://github.com/cmaloney/cpython/commit/4204a1e41182dc13d7e752e68455eb8b71be6418
pythongh-161714https://github.com/python/cpython/issues/161714
4204a1ehttps://github.com/cmaloney/cpython/commit/4204a1e41182dc13d7e752e68455eb8b71be6418
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Nov 15, 2026https://github.com/python/cpython/issues/161714#issuecomment-6888783510
cmaloney@56beb44https://github.com/cmaloney/cpython/commit/56beb44c57b1890723f74844b706635621133e96
#160401https://github.com/python/cpython/pull/160401
#161455https://github.com/python/cpython/pull/161455
#161793https://github.com/python/cpython/pull/161793
https://github.com/colesbury
colesburyhttps://github.com/colesbury
on Nov 15, 2026https://github.com/python/cpython/issues/161714#issuecomment-6896802287
https://xkcd.com/927/https://xkcd.com/927/
https://github.com/cmaloney
cmaloneyhttps://github.com/cmaloney
on Nov 15, 2026https://github.com/python/cpython/issues/161714#issuecomment-6901084921
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/161714
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/161714
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%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
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.