René's URL Explorer Experiment


Title: Free-threaded CPython 3.14: concurrent functools.partial.__setstate__ crashes with repr(), calls, or another __setstate__ · Issue #157841 · python/cpython · GitHub

Open Graph Title: Free-threaded CPython 3.14: concurrent functools.partial.__setstate__ crashes with repr(), calls, or another __setstate__ · Issue #157841 · python/cpython

X Title: Free-threaded CPython 3.14: concurrent functools.partial.__setstate__ crashes with repr(), calls, or another __setstate__ · Issue #157841 · python/cpython

Description: Prior report gh-157099 (2026-09-07) reported the same missing synchronization in partial_setstate, reaching it through partial_new (a crash in tuple_concat under ASan, 3.14.7 @ 823f032). It was closed by its reporter after a request to c...

Open Graph Description: Prior report gh-157099 (2026-09-07) reported the same missing synchronization in partial_setstate, reaching it through partial_new (a crash in tuple_concat under ASan, 3.14.7 @ 823f032). It was clo...

X Description: Prior report gh-157099 (2026-09-07) reported the same missing synchronization in partial_setstate, reaching it through partial_new (a crash in tuple_concat under ASan, 3.14.7 @ 823f032). It was clo...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Free-threaded CPython 3.14: concurrent functools.partial.__setstate__ crashes with repr(), calls, or another __setstate__","articleBody":"### Prior report\n\ngh-157099 (2026-09-07) reported the same missing synchronization in `partial_setstate`, reaching it through `partial_new` (a crash in `tuple_concat` under ASan, 3.14.7 @ 823f032). It was closed by its reporter after a request to consolidate a batch of reports (gh-157124), and the consolidated issues gh-157196 / gh-157197 / gh-157198 were then withdrawn by the reporter on 2026-09-11 to be resubmitted under the security policy. As far as I can see nothing tracks it now, and `main` @ 89c67a9 still crashes. This report was found independently (static analysis of `partial_repr` on 3.14.0rc1, then runtime confirmation) and adds a sanitizer-free 25-line reproducer covering `repr()`, calls and writer/writer, with a GIL control on the same binary. If you would rather reopen gh-157099, please close this one as a duplicate. Filed on the public tracker because triggering it requires running Python code in the process (the assessment given on gh-157196).\n\n### What happened?\n\nOn the free-threaded build, calling `partial.__setstate__` on a `functools.partial` object while another thread uses the same object (`repr(p)` or `p()`), or while a second thread also calls `__setstate__`, crashes the interpreter within seconds. The read-only control completed all five four-second runs without a crash. The same binary with `PYTHON_GIL=1` completed every run without a crash.\n\nStandalone reproducer (`repro_partial.py \u003cmode>`):\n\n```python\nimport functools, itertools, os, sys, threading\nif os.environ.get(\"ALLOW_GIL\") != \"1\":\n    assert not sys._is_gil_enabled()\nmode = sys.argv[1]\ncounter = itertools.count(10**12)          # fresh heap ints, never cached\ndef fresh(): return next(counter)\ndef f(*a, **k): return None\np = functools.partial(f, fresh(), fresh())\nstop = threading.Event()\ndef reader_repr(): repr(p)\ndef reader_call(): p()\ndef writer(): p.__setstate__((f, (fresh(), fresh()), {}, None))\nreader, nr, nw = {\"ro\": (reader_repr, 4, 0), \"rw\": (reader_repr, 4, 1),\n                  \"ww\": (None, 0, 2), \"cw\": (reader_call, 4, 1)}[mode]\ndef loop(fn):\n    while not stop.is_set():\n        fn()\nts = [threading.Thread(target=loop, args=(reader,)) for _ in range(nr)] + \\\n     [threading.Thread(target=loop, args=(writer,)) for _ in range(nw)]\nfor t in ts: t.start()\nstop.wait(4); stop.set()\nfor t in ts: t.join()\nprint(\"ok\")\n```\n\nResults, 5 runs × 4 s per mode, run with `-X faulthandler` (\"hang\" = the process had not exited 30 s after start and was killed):\n\n| mode | threads | 3.14.6t | 3.14.6t, `PYTHONMALLOC=debug` | same binary, `PYTHON_GIL=1` | `main` @ 89c67a9 (`--disable-gil`) | `main`, `PYTHONMALLOC=debug` |\n|---|---|---|---|---|---|---|\n| `ro` | 4 × `repr(p)` | 5/5 ok | 5/5 ok | — | 5/5 ok | 5/5 ok |\n| `rw` | 4 × `repr(p)` + 1 × `__setstate__` | **0/5** (SIGILL, SIGABRT, 3 hangs) | **0/5** (SIGSEGV ×5) | 3/3 ok | **0/5** (SIGABRT ×2, SIGILL, 2 hangs) | **0/5** (SIGSEGV ×5) |\n| `ww` | 2 × `__setstate__` | 4/5 (SIGSEGV ×1) | 1/5 (SIGSEGV ×4) | 3/3 ok | 2/5 (SIGSEGV ×3) | 4/5 (SIGSEGV ×1) |\n| `cw` | 4 × `p()` + 1 × `__setstate__` | **0/5** (SIGILL ×2, SIGTRAP ×2, SIGSEGV) | **0/5** (SIGSEGV ×5) | 3/3 ok | **0/5** (SIGSEGV ×3, SIGILL, 1 hang) | **0/5** (SIGSEGV ×5) |\n\n`ww` is intermittent: over several runs of this script today it crashed in 1 to 4 of 5 runs per configuration. `rw` and `cw` failed in every run of every free-threaded configuration. The SIGABRT cases are\n\n```\nFatal Python error: PyMutex_Unlock: unlocking mutex that is not locked\n```\n\nraised from the `repr` thread (faulthandler shows `reader_repr`). The `repr`/`__setstate__` shape also crashes on 3.14.0rc1 free-threaded (5/5, `PYTHONMALLOC=debug`). Note that `main` already carries the `partial_vectorcall` snapshot from gh-154189, and `cw` still crashes there.\n\n### Analysis\n\n`partial_setstate` replaces `pto->fn`, `pto->args` and `pto->kw` with `Py_SETREF` and holds no critical section on the partial object (3.13 branch `Modules/_functoolsmodule.c:514`; 3.14 branch `:762`; `main` `:857`). The readers take strong references from the fields — `partial_repr` since gh-144475 (3.14 branch `:630`), `partial_vectorcall` since gh-154189 (`main` only; not in 3.14). The source suggests an unsynchronized reference-acquisition gap: `Py_NewRef(pto->args)` does not protect the interval between loading the field and acquiring a strong reference while another thread replaces it. The observed crashes have not yet been attributed to a particular native access. Two concurrent `__setstate__` writers also crash without a reader thread; the failing access in that case has not yet been identified. gh-144475 and gh-154189 addressed the re-entrant, same-thread shape of this; gh-157099 and this report are the cross-thread shape.\n\n### Expected behaviour\n\nI expect concurrent use to avoid interpreter crashes; no particular ordering or consistent result is required by this reproducer. The free-threading HOWTO says the build \"aims to provide similar thread-safety behavior at the Python level to the default GIL-enabled build\" while noting that this \"should be treated as a description of the current implementation, not a guarantee\"; the same binary with the GIL enabled runs the reproducer without a crash.\n\n### Possible approach\n\nA possible approach is to synchronize state publication and acquisition of coherent reader snapshots on the partial object, including associated placeholder and vectorcall state; the complete access and reentrancy audit remains to be done. Happy to test a patch.\n\n### CPython versions tested on\n\n3.14.6 (free-threaded, python-build-standalone via uv), 3.14.0rc1 (free-threaded), CPython main branch @ 89c67a9 (2026-09-20, local `--disable-gil` build; `Modules/_functoolsmodule.c` identical to upstream at that commit)\n\n### Operating systems tested on\n\nmacOS (arm64, Darwin 25.6)\n\n### Output from running 'python -VV' on the command line\n\n```\nPython 3.14.6 free-threading build (main, Jul 18 2026, 17:07:52) [Clang 22.1.3 ]\nPython 3.16.0a0 free-threading build (remotes/origin/HEAD-dirty:89c67a9, Sep 20 2026, 14:12:46) [Clang 21.0.0 (clang-2100.3.34.2)]\n```\n\n### Related\n\ngh-157099 (same root cause, closed not_planned), gh-144475, gh-154189, gh-140590\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157979\n* gh-160480\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/espressolee","@type":"Person","name":"espressolee"},"datePublished":"2026-09-20T07:06:45Z","url":"https://github.com/python/cpython/issues/157841"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:aa6f2f23-dabb-d8eb-94db-f23bec7723ab
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idC032:8BA7F:77D8D8:A61A89:6AF85843
html-safe-nonce8a37478072646ec009d5c27e6f2d1afc2b78e37754538612f6da80ac4e18d8ab
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDMyOjhCQTdGOjc3RDhEODpBNjFBODk6NkFGODU4NDMiLCJ2aXNpdG9yX2lkIjoiMzIwNTAzMjU1ODAzMDUxMDE0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac1c88b9a6898f856bd3ab33d7b91d53037b3e7a8fe367dd32d82ae2a62b3f633a
hovercard-subject-tagissue:5516367783
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/157841/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d727576e68389d21c12eb45bcf9e152f15fbcfcdaf1be9badfa8a4f76e89fa07/python/cpython/issues/157841
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d727576e68389d21c12eb45bcf9e152f15fbcfcdaf1be9badfa8a4f76e89fa07/python/cpython/issues/157841
og:image:altPrior report gh-157099 (2026-09-07) reported the same missing synchronization in partial_setstate, reaching it through partial_new (a crash in tuple_concat under ASan, 3.14.7 @ 823f032). It was clo...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameespressolee
hostnamegithub.com
expected-hostnamegithub.com
None5713ecd83001b2f55c3509fb7a292bf7d66d0f167c7ae87a9f7eaec5a52bf8db
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
release653be32ff5c755082a4db662491bfbbcfc9112c1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/157841#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F157841
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%2F157841
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/157841
Reloadhttps://github.com/python/cpython/issues/157841
Reloadhttps://github.com/python/cpython/issues/157841
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/pulse
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/157841
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/157841
Free-threaded CPython 3.14: concurrent functools.partial.__setstate__ crashes with repr(), calls, or another __setstate__https://github.com/python/cpython/issues/157841#top
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-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/espressolee
espressoleehttps://github.com/espressolee
on Sep 20, 2026https://github.com/python/cpython/issues/157841#issue-5516367783
gh-157099https://github.com/python/cpython/issues/157099
gh-157124https://github.com/python/cpython/issues/157124
gh-157196https://github.com/python/cpython/issues/157196
gh-157197https://github.com/python/cpython/issues/157197
gh-157198https://github.com/python/cpython/issues/157198
gh-157099https://github.com/python/cpython/issues/157099
gh-157196https://github.com/python/cpython/issues/157196
gh-154189https://github.com/python/cpython/issues/154189
gh-144475https://github.com/python/cpython/issues/144475
gh-154189https://github.com/python/cpython/issues/154189
gh-144475https://github.com/python/cpython/issues/144475
gh-154189https://github.com/python/cpython/issues/154189
gh-157099https://github.com/python/cpython/issues/157099
gh-157099https://github.com/python/cpython/issues/157099
gh-144475https://github.com/python/cpython/issues/144475
gh-154189https://github.com/python/cpython/issues/154189
gh-140590https://github.com/python/cpython/issues/140590
gh-157841: Synchronize access to functools.partial's mutable state #157979https://github.com/python/cpython/pull/157979
gh-157841: Synchronize functools.partial state access #160480https://github.com/python/cpython/pull/160480
aiskhttps://github.com/aisk
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%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
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
on Sep 20, 2026https://github.com/python/cpython/issues/157841#event-31475736730
https://github.com/Adarsh-Me
Adarsh-Mehttps://github.com/Adarsh-Me
on Sep 21, 2026https://github.com/python/cpython/issues/157841#issuecomment-5757850175
gh-157196https://github.com/python/cpython/issues/157196
https://github.com/espressolee
espressoleehttps://github.com/espressolee
on Sep 21, 2026https://github.com/python/cpython/issues/157841#issuecomment-5758474593
gh-157196https://github.com/python/cpython/issues/157196
gh-157099https://github.com/python/cpython/issues/157099
gh-157124https://github.com/python/cpython/issues/157124
gh-157196https://github.com/python/cpython/issues/157196
gh-157099https://github.com/python/cpython/issues/157099
https://github.com/Adarsh-Me
Adarsh-Mehttps://github.com/Adarsh-Me
on Sep 23, 2026https://github.com/python/cpython/issues/157841#issuecomment-5791106217
#157979https://github.com/python/cpython/pull/157979
@espressoleehttps://github.com/espressolee
#157979https://github.com/python/cpython/pull/157979
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/157841#event-33592125542
github-project-automationhttps://github.com/apps/github-project-automation
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/157841
kevinprimeraquecreo-stackhttps://github.com/kevinprimeraquecreo-stack
Project_VKhttps://github.com/users/kevinprimeraquecreo-stack/projects/1
on Oct 18, 2026https://github.com/python/cpython/issues/157841#event-33592175932
https://github.com/espressolee
espressoleehttps://github.com/espressolee
on Oct 19, 2026https://github.com/python/cpython/issues/157841#issuecomment-6264288509
#157979https://github.com/python/cpython/pull/157979
#157979https://github.com/python/cpython/pull/157979
#157979 (comment)https://github.com/python/cpython/pull/157979#issuecomment-5902447960
#157979https://github.com/python/cpython/pull/157979
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/157841
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/157841
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-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.