René's URL Explorer Experiment


Title: Data race: `TextIOWrapper.detach()` stores `self->buffer = NULL` non-atomically · Issue #154523 · python/cpython · GitHub

Open Graph Title: Data race: `TextIOWrapper.detach()` stores `self->buffer = NULL` non-atomically · Issue #154523 · python/cpython

X Title: Data race: `TextIOWrapper.detach()` stores `self->buffer = NULL` non-atomically · Issue #154523 · python/cpython

Description: Bug report Bug description: In the free-threaded build, TextIOWrapper.detach() clears the self->buffer slot with a plain store, while reading tw.buffer goes through a LOAD_ATTR_SLOT specialization that reads the same slot with FT_ATOMIC_...

Open Graph Description: Bug report Bug description: In the free-threaded build, TextIOWrapper.detach() clears the self->buffer slot with a plain store, while reading tw.buffer goes through a LOAD_ATTR_SLOT specialization ...

X Description: Bug report Bug description: In the free-threaded build, TextIOWrapper.detach() clears the self->buffer slot with a plain store, while reading tw.buffer goes through a LOAD_ATTR_SLOT specializati...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Data race: `TextIOWrapper.detach()` stores `self->buffer = NULL` non-atomically","articleBody":"# Bug report\n\n### Bug description:\n\nIn the free-threaded build, `TextIOWrapper.detach()` clears the `self->buffer` slot with a plain store, while reading `tw.buffer` goes through a `LOAD_ATTR_SLOT` specialization that reads the same slot with `FT_ATOMIC_LOAD_PTR`.\n\nWriter — `_io_TextIOWrapper_detach_impl`:\nhttps://github.com/python/cpython/blob/a2a846678e54b1b5defdccd451c573679094ff02/Modules/_io/textio.c#L1630-L1645\n\nReader — `LOAD_ATTR_SLOT` reads the slot atomically:\nhttps://github.com/python/cpython/blob/a2a846678e54b1b5defdccd451c573679094ff02/Python/generated_cases.c.h#L9493-L9503\n\nSo `tw.buffer` racing `tw.detach()` is a plain-store-vs-atomic-load data race on the `buffer` slot. `detach()` should store the slot atomically.\n\nReproducer:\n```python\nimport io\nfrom threading import Thread\n\ndef make():\n    return io.TextIOWrapper(io.BytesIO(b'x' * 16))\n\nslot = [make()]\n\ndef reader():\n    for _ in range(20000):\n        try:\n            _ = slot[0].buffer\n        except Exception:\n            pass\n\ndef detacher():\n    for _ in range(20000):\n        try:\n            slot[0].detach()\n        except Exception:\n            pass\n        slot[0] = make()\n\nthreads  = [Thread(target=reader)   for _ in range(6)]\nthreads += [Thread(target=detacher) for _ in range(2)]\nfor t in threads: t.start()\nfor t in threads: t.join()\n```\n\nTSAN Report:\n```\nWARNING: ThreadSanitizer: data race (pid=1522499)\n  Write of size 8 at 0x7fffd0100110 by thread T7:\n    #0 _io_TextIOWrapper_detach_impl /cpython/./Modules/_io/textio.c:1642:18\n    #1 _io_TextIOWrapper_detach /cpython/./Modules/_io/clinic/textio.c.h:793:20\n    #2 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:4330:35\n\n  Previous atomic read of size 8 at 0x7fffd0100110 by thread T6:\n    #0 _Py_atomic_load_ptr /cpython/./Include/cpython/pyatomic_gcc.h:300:18 \n    #1 _PyEval_EvalFrameDefault /cpython/Python/generated_cases.c.h:9588:36\n    #2 _PyEval_EvalFrame /cpython/./Include/internal/pycore_ceval.h:122:16 \n\nSUMMARY: ThreadSanitizer: data race /cpython/./Modules/_io/textio.c:1642:18 in _io_TextIOWrapper_detach_impl\n==================\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS, Linux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-154565\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/Naserume","@type":"Person","name":"Naserume"},"datePublished":"2026-07-23T05:05:25Z","url":"https://github.com/python/cpython/issues/154523"}

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:d9b186f4-8009-6abb-f828-425757c63d3f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB8A8:38E318:2FE3DFF:3CABBE9:6B01FA43
html-safe-nonce26c2743238cde8b663213acfb51cca21110d69952a9d106254e034b2c60e995d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOEE4OjM4RTMxODoyRkUzREZGOjNDQUJCRTk6NkIwMUZBNDMiLCJ2aXNpdG9yX2lkIjoiNzUwMDkwOTgyMDE2MjIxMDM3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac959cb87d85caba67263e63969977bb3bc04580a12881abfd0af1b2bad90f531d
hovercard-subject-tagissue:4955635627
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/154523/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6ab032ebc7b20ffe8227b0fb26e12162e0c71e226e46e70c46c61328870d9f46/python/cpython/issues/154523
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6ab032ebc7b20ffe8227b0fb26e12162e0c71e226e46e70c46c61328870d9f46/python/cpython/issues/154523
og:image:altBug report Bug description: In the free-threaded build, TextIOWrapper.detach() clears the self->buffer slot with a plain store, while reading tw.buffer goes through a LOAD_ATTR_SLOT specialization ...
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/154523#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F154523
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%2F154523
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/154523
Reloadhttps://github.com/python/cpython/issues/154523
Reloadhttps://github.com/python/cpython/issues/154523
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/154523
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/154523
Data race: TextIOWrapper.detach() stores self->buffer = NULL non-atomicallyhttps://github.com/python/cpython/issues/154523#top
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-IOhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-IO%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 23, 2026https://github.com/python/cpython/issues/154523#issue-4955635627
cpython/Modules/_io/textio.chttps://github.com/python/cpython/blob/a2a846678e54b1b5defdccd451c573679094ff02/Modules/_io/textio.c#L1630-L1645
a2a8466https://github.com/python/cpython/commit/a2a846678e54b1b5defdccd451c573679094ff02
cpython/Python/generated_cases.c.hhttps://github.com/python/cpython/blob/a2a846678e54b1b5defdccd451c573679094ff02/Python/generated_cases.c.h#L9493-L9503
a2a8466https://github.com/python/cpython/commit/a2a846678e54b1b5defdccd451c573679094ff02
gh-154523: Fix data-race in TextIOWrapper.detach() #154565https://github.com/python/cpython/pull/154565
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 23, 2026https://github.com/python/cpython/issues/154523#event-28363409902
StanFromIrelandhttps://github.com/StanFromIreland
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-IOhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-IO%22
topic-free-threadinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-free-threading%22
on Jul 23, 2026https://github.com/python/cpython/issues/154523#event-28369580401
https://github.com/devdanzin
devdanzinhttps://github.com/devdanzin
on Jul 23, 2026https://github.com/python/cpython/issues/154523#issuecomment-5057411520
https://github.com/kumaraditya303
kumaraditya303https://github.com/kumaraditya303
on Jul 30, 2026https://github.com/python/cpython/issues/154523#issuecomment-5132501458
kumaraditya303https://github.com/kumaraditya303
on Aug 4, 2026https://github.com/python/cpython/issues/154523#event-28951695778
gh-154523: Fix data-race in `TextIOWrapper.detach()` (#154565)https://github.com/python/cpython/commit/8440a6a4651f93ecd1c7768ffb2c735c5b9fb984
gh-154523https://github.com/python/cpython/issues/154523
#154565https://github.com/python/cpython/pull/154565
8440a6ahttps://github.com/python/cpython/commit/8440a6a4651f93ecd1c7768ffb2c735c5b9fb984
kumaraditya303https://github.com/kumaraditya303
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 4, 2026https://github.com/python/cpython/issues/154523#event-28951705421
mbeijenhttps://github.com/mbeijen
on Aug 14, 2026https://github.com/python/cpython/issues/154523#event-29455499505
pythongh-154523: Fix data-race in `TextIOWrapper.detach()` (python#15…https://github.com/mbeijen/cpython/commit/8642dd03ec00513addd6bb0eabc8f2b4e499cc6c
pythongh-154523https://github.com/python/cpython/issues/154523
python#15…https://github.com/python/cpython/pull/154565
8642dd0https://github.com/mbeijen/cpython/commit/8642dd03ec00513addd6bb0eabc8f2b4e499cc6c
vstinnerhttps://github.com/vstinner
on Oct 16, 2026https://github.com/python/cpython/issues/154523#event-33491208519
[3.15] gh-157364: Fix use-after-free in io.TextIOWrapper during reent…https://github.com/python/cpython/commit/ea1312bdb446a536964ec7133625ae6aa6a592bf
gh-157364https://github.com/python/cpython/issues/157364
ea1312bhttps://github.com/python/cpython/commit/ea1312bdb446a536964ec7133625ae6aa6a592bf
[3.14] gh-157364: Fix use-after-free in io.TextIOWrapper during reent…https://github.com/python/cpython/commit/13fc16c9c0e2b2055aa1d01c93cff2e8b50c445c
gh-157364https://github.com/python/cpython/issues/157364
13fc16chttps://github.com/python/cpython/commit/13fc16c9c0e2b2055aa1d01c93cff2e8b50c445c
cmaloneyhttps://github.com/cmaloney
on Nov 5, 2026https://github.com/python/cpython/issues/154523#event-35289715627
gh-160427: Return None from TextIOWrapper.buffer when detached (#160802)https://github.com/python/cpython/commit/3422197f5481ac1b3134e2633332415a02959ba4
gh-160427https://github.com/python/cpython/issues/160427
#160802https://github.com/python/cpython/pull/160802
3422197https://github.com/python/cpython/commit/3422197f5481ac1b3134e2633332415a02959ba4
[3.15] gh-160427: Return None from TextIOWrapper.buffer when detached (…https://github.com/python/cpython/commit/4af98bdb94beb37453a33b989f8ef466f8ef0e21
gh-160427https://github.com/python/cpython/issues/160427
…https://github.com/python/cpython/pull/160802
4af98bdhttps://github.com/python/cpython/commit/4af98bdb94beb37453a33b989f8ef466f8ef0e21
[3.14] gh-160427: Return None from TextIOWrapper.buffer when detached (…https://github.com/python/cpython/commit/9106913d96becf2f06be1e312e46877adccfa6e8
gh-160427https://github.com/python/cpython/issues/160427
…https://github.com/python/cpython/pull/160802
9106913https://github.com/python/cpython/commit/9106913d96becf2f06be1e312e46877adccfa6e8
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/154523
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/154523
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
topic-IOhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-IO%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.