René's URL Explorer Experiment


Title: segfault in ga_iternext: sharing a types.GenericAlias iterator across threads double-frees under free-threading · Issue #154043 · python/cpython · GitHub

Open Graph Title: segfault in ga_iternext: sharing a types.GenericAlias iterator across threads double-frees under free-threading · Issue #154043 · python/cpython

X Title: segfault in ga_iternext: sharing a types.GenericAlias iterator across threads double-frees under free-threading · Issue #154043 · python/cpython

Description: Crash report What happened? On a free-threaded (--disable-gil) build, iterating a single, shared types.GenericAlias iterator (e.g. iter(list[int])) from multiple threads segfaults. ga_iternext (Objects/genericaliasobject.c) is a one-shot...

Open Graph Description: Crash report What happened? On a free-threaded (--disable-gil) build, iterating a single, shared types.GenericAlias iterator (e.g. iter(list[int])) from multiple threads segfaults. ga_iternext (Obj...

X Description: Crash report What happened? On a free-threaded (--disable-gil) build, iterating a single, shared types.GenericAlias iterator (e.g. iter(list[int])) from multiple threads segfaults. ga_iternext (Obj...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"segfault in ga_iternext: sharing a types.GenericAlias iterator across threads double-frees under free-threading","articleBody":"# Crash report\n\n### What happened?\n\nOn a free-threaded (`--disable-gil`) build, iterating a single, shared `types.GenericAlias` iterator (e.g. `iter(list[int])`) from multiple threads segfaults. `ga_iternext` (`Objects/genericaliasobject.c`) is a one-shot iterator with no synchronization:\n\n```c\nstatic PyObject *\nga_iternext(PyObject *op)\n{\n    gaiterobject *gi = (gaiterobject *)op;\n    if (gi->obj == NULL) {                               // read gi->obj\n        PyErr_SetNone(PyExc_StopIteration);\n        return NULL;\n    }\n    gaobject *alias = (gaobject *)gi->obj;\n    PyObject *starred_alias = Py_GenericAlias(alias->origin, alias->args);   // use gi->obj\n    if (starred_alias == NULL)\n        return NULL;\n    ((gaobject *)starred_alias)->starred = true;\n    Py_SETREF(gi->obj, NULL);                            // Py_DECREF(gi->obj); gi->obj = NULL\n    return starred_alias;\n}\n```\n\nTwo threads both observe `gi->obj != NULL`, both build the starred alias from it, and both reach `Py_SETREF(gi->obj, NULL)` (which is `tmp = gi->obj; gi->obj = NULL; Py_DECREF(tmp)`). With `gi->obj`'s refcount at 1 (the iterator is its only holder), the two `Py_DECREF`s free it twice — a double-free / refcount underflow — and the reads of `alias->origin`/`alias->args` become a use-after-free once the other thread frees it. The process crashes.\n\n### Reproducer\n\n```python\nimport threading\n\nNT = 16\n\ndef worker(it, barrier):\n    barrier.wait()\n    try:\n        next(it)\n    except StopIteration:\n        pass\n\nfor _round in range(20000):\n    shared = iter(list[int])      # ONE shared GenericAlias iterator; gi->obj refcount == 1\n    bar = threading.Barrier(NT)\n    threads = [threading.Thread(target=worker, args=(shared, bar)) for _ in range(NT)]\n    for t in threads:\n        t.start()\n    for t in threads:\n        t.join()\nprint(\"done\")\n```\n\n`PYTHON_GIL=0 ./python repro.py` segfaults within the first few rounds — 5/5 runs on both a debug and a release (`-O0`, no sanitizer) free-threaded build, so it is neither debug-only nor sanitizer-only:\n\n```\nThread NNNN received signal SIGSEGV, Segmentation fault.\n#0  ga_iternext (op=...) at Objects/genericaliasobject.c:952        (Py_SETREF(gi->obj, NULL))\n#1  builtin_next                Python/bltinmodule.c:1776\n#2  _Py_BuiltinCallFast_StackRef Python/ceval.c:817\n#3  _PyEval_EvalFrameDefault     Python/generated_cases.c.h:2510    (next(it))\n...\n```\n\nThreadSanitizer reports the same as a data race on `gi->obj` (`WARNING: ThreadSanitizer: data race... in ga_iternext`, exit 66).\n\n### Suggested fix\n\nConsume `gi->obj` atomically so exactly one thread takes it:\n\n```c\nPyObject *obj = _Py_atomic_exchange_ptr(&gi->obj, NULL);\nif (obj == NULL) {\n    PyErr_SetNone(PyExc_StopIteration);\n    return NULL;\n}\ngaobject *alias = (gaobject *)obj;\nPyObject *starred_alias = Py_GenericAlias(alias->origin, alias->args);\nif (starred_alias == NULL) {\n    Py_DECREF(obj);\n    return NULL;\n}\n((gaobject *)starred_alias)->starred = true;\nPy_DECREF(obj);\nreturn starred_alias;\n```\n\n(Or wrap the body in `Py_BEGIN_CRITICAL_SECTION(gi)`.) This matches the \"consume once\" semantics and keeps the GIL build unchanged.\n\nPer the iterator free-threading strategy (gh-124397), concurrent iteration may return duplicate or skipped values or raise — but it must not crash; this crashes. Distinct from gh-153298, which is the `GenericAlias.__parameters__` lazy-init race, not the iterator.\n\n*(Found by `fusil --tsan`, a ThreadSanitizer fuzzer; crash confirmed by re-running the reproducer without a sanitizer on a plain free-threaded build. Draft and reproducer by Claude Code, minimized and reviewed by hand.)*\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.16.0a0 free-threading build (heads/main:a1d580430c8, Jul 18 2026, 20:36:44) [Clang 21.1.8 (6ubuntu1)]\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154108\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/devdanzin","@type":"Person","name":"devdanzin"},"datePublished":"2026-07-19T03:07:31Z","url":"https://github.com/python/cpython/issues/154043"}

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:2ec853b5-25de-fb93-c838-2de26bfaf75d
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC530:2BE220:36C2582:48FE07D:6B0211F5
html-safe-nonce7a4881d995a1cc659ea58d1a9da36fce00ed367000cf5167facf60be862a1953
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTMwOjJCRTIyMDozNkMyNTgyOjQ4RkUwN0Q6NkIwMjExRjUiLCJ2aXNpdG9yX2lkIjoiNTQzMTU3MjI4MTc3NDE4MjkwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace0cd54c63f18268cd9450cb8a830458f17f1503c11f507f0f0461cd9bb9658f8
hovercard-subject-tagissue:4921049479
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/154043/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5075606011f378a77994fc4efa82e70882a0a862baa744302f276ac99003c630/python/cpython/issues/154043
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5075606011f378a77994fc4efa82e70882a0a862baa744302f276ac99003c630/python/cpython/issues/154043
og:image:altCrash report What happened? On a free-threaded (--disable-gil) build, iterating a single, shared types.GenericAlias iterator (e.g. iter(list[int])) from multiple threads segfaults. ga_iternext (Obj...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedevdanzin
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/154043#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F154043
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%2F154043
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/154043
Reloadhttps://github.com/python/cpython/issues/154043
Reloadhttps://github.com/python/cpython/issues/154043
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/154043
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154043
segfault in ga_iternext: sharing a types.GenericAlias iterator across threads double-frees under free-threadinghttps://github.com/python/cpython/issues/154043#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-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/devdanzin
devdanzinhttps://github.com/devdanzin
on Jul 19, 2026https://github.com/python/cpython/issues/154043#issue-4921049479
gh-124397https://github.com/python/cpython/issues/124397
gh-153298https://github.com/python/cpython/issues/153298
gh-154043: Fix a data race when iterating a shared types.GenericAlias iterator in FT build #154108https://github.com/python/cpython/pull/154108
devdanzinhttps://github.com/devdanzin
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%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 Jul 19, 2026https://github.com/python/cpython/issues/154043#event-28171488123
kumaraditya303https://github.com/kumaraditya303
on Jul 25, 2026https://github.com/python/cpython/issues/154043#event-28471474711
gh-154043: Fix a data race when iterating a shared `types.GenericAlia…https://github.com/python/cpython/commit/e31d30266f33198d92e5adbbc055f6595555726d
gh-154043https://github.com/python/cpython/issues/154043
e31d302https://github.com/python/cpython/commit/e31d30266f33198d92e5adbbc055f6595555726d
kumaraditya303https://github.com/kumaraditya303
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jul 25, 2026https://github.com/python/cpython/issues/154043#event-28471476459
mbeijenhttps://github.com/mbeijen
on Aug 14, 2026https://github.com/python/cpython/issues/154043#event-29455490192
pythongh-154043: Fix a data race when iterating a shared `types.Gener…https://github.com/mbeijen/cpython/commit/ca923ffcb84b34a9b07806acf4e6ebc0bc85ad5d
pythongh-154043https://github.com/python/cpython/issues/154043
ca923ffhttps://github.com/mbeijen/cpython/commit/ca923ffcb84b34a9b07806acf4e6ebc0bc85ad5d
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/154043
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/154043
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-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%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.