René's URL Explorer Experiment


Title: Using _testcapi.set_nomemory() in a test triggers a ThreadSanitizer "data race" · Issue #157415 · python/cpython · GitHub

Open Graph Title: Using _testcapi.set_nomemory() in a test triggers a ThreadSanitizer "data race" · Issue #157415 · python/cpython

X Title: Using _testcapi.set_nomemory() in a test triggers a ThreadSanitizer "data race" · Issue #157415 · python/cpython

Description: I recently added a test in test_io.test_memoryio using _testcapi.set_nomemory() to inject a MemoryError: commit 23eda00. The test was flagged as "data race" by clang ThreadSanitizer on a GHA CI run. The main thread calls _testcapi.set_no...

Open Graph Description: I recently added a test in test_io.test_memoryio using _testcapi.set_nomemory() to inject a MemoryError: commit 23eda00. The test was flagged as "data race" by clang ThreadSanitizer on a GHA CI run...

X Description: I recently added a test in test_io.test_memoryio using _testcapi.set_nomemory() to inject a MemoryError: commit 23eda00. The test was flagged as "data race" by clang ThreadSanitizer on a ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Using _testcapi.set_nomemory() in a test triggers a ThreadSanitizer \"data race\"","articleBody":"I recently added a test in `test_io.test_memoryio` using `_testcapi.set_nomemory()` to inject a MemoryError: commit 23eda007f8d543495ba4935df75d243d76f9ef7f. The test was flagged as \"data race\" by clang ThreadSanitizer on a [GHA CI run](https://github.com/python/cpython/actions/runs/34737711156/job/103672505968?pr=157382).\n\n* The main thread calls `_testcapi.set_nomemory()` which calls `PyMem_SetAllocator()` which is implemented as `set_allocator_unlocked()`: its writes into `_PyRuntime.allocators.standard.raw` (type `PyMemAllocatorEx`).\n* The faulthandler thread calls `PyMem_RawFree()` which reads from `_PyRuntime.allocators.standard.raw`.\n\n`PyMem_SetAllocator()` acquires a lock, but `PyMem_RawFree()` doesn't acquire this lock.\n\nThis race condition was already seen with `tracemalloc`:\n\n* https://github.com/python/cpython/issues/143143#issuecomment-4081656148\n* https://github.com/python/cpython/issues/126315#issuecomment-3048731039\n\nUsing `_testcapi.set_nomemory()` in a multithreaded application is used, but this function should only be used for testing purpose. So I propose skipping the test if Python is built with TSAN (`./configure --with-thread-sanitizer` with clang).\n\nLogs:\n\n```\nWARNING: ThreadSanitizer: data race (pid=15518)\n  Write of size 8 at 0x55b013af2f80 by main thread:\n    #0 __tsan_memcpy \u003cnull> (python+0xfc452) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #1 set_allocator_unlocked /home/runner/work/cpython/cpython/Objects/obmalloc.c (python+0x38417f) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #2 PyMem_SetAllocator /home/runner/work/cpython/cpython/Objects/obmalloc.c:1143:5 (python+0x38417f)\n    #3 fm_setup_hooks /home/runner/work/cpython/cpython/./Modules/_testcapi/mem.c:160:5 (_testcapi.cpython-316d-x86_64-linux-gnu.so+0x353e9) (BuildId: 97ab4e2a64a9d371fd1394f000a763262bd7b835)\n    #4 fm_set_nomemory /home/runner/work/cpython/cpython/./Modules/_testcapi/mem.c:189:5 (_testcapi.cpython-316d-x86_64-linux-gnu.so+0x353e9)\n    #5 set_nomemory /home/runner/work/cpython/cpython/./Modules/_testcapi/mem.c:202:5 (_testcapi.cpython-316d-x86_64-linux-gnu.so+0x34590) (BuildId: 97ab4e2a64a9d371fd1394f000a763262bd7b835)\n    #6 cfunction_call /home/runner/work/cpython/cpython/Objects/methodobject.c:575:18 (python+0x34e22f) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #7 _PyObject_MakeTpCall /home/runner/work/cpython/cpython/Objects/call.c:242:18 (python+0x29318b) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #8 _PyObject_VectorcallTstate /home/runner/work/cpython/cpython/./Include/internal/pycore_call.h:142:16 (python+0x292ac9) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #9 PyObject_Vectorcall /home/runner/work/cpython/cpython/Objects/call.c:327:12 (python+0x294410) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n   (...)\n\n  Previous read of size 8 at 0x55b013af2f80 by thread T1:\n    #0 PyMem_RawFree /home/runner/work/cpython/cpython/Objects/obmalloc.c:1239:5 (python+0x384578) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #1 pythread_wrapper /home/runner/work/cpython/cpython/Python/thread_pthread.h:234:5 (python+0x66c445) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n\n  Location is global '_PyRuntime' of size 266672 at 0x55b013af2b70 (python+0xa46f80)\n\n  Thread T1 (tid=15538, running) created by main thread at:\n    #0 pthread_create \u003cnull> (python+0x1010de) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #1 do_start_joinable_thread /home/runner/work/cpython/cpython/Python/thread_pthread.h:283:14 (python+0x66b1db) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #2 PyThread_start_new_thread /home/runner/work/cpython/cpython/Python/thread_pthread.h:338:9 (python+0x66b28a) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #3 faulthandler_dump_traceback_later_impl /home/runner/work/cpython/cpython/./Modules/faulthandler.c:883:9 (python+0x6a4c64) (BuildId: 77d4ccbb4bf7bb80d66adcdbb8a43d9cd1f555bc)\n    #4 faulthandler_dump_traceback_later /home/runner/work/cpython/cpython/./Modules/clinic/faulthandler.c.h:439:20 (python+0x6a4c64)\n   (...)\n```\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-157416\n* gh-157430\n* gh-159277\n* gh-159547\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2026-09-13T12:03:05Z","url":"https://github.com/python/cpython/issues/157415"}

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:f7cabab2-0168-b181-70c8-a3040c362b29
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id956C:136CDA:11C8E02:1792D69:6B01E850
html-safe-nonce861c21698d9ae0db1ba15f988caf0c0c87d8797001769fd5715775f15023f33e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTZDOjEzNkNEQToxMUM4RTAyOjE3OTJENjk6NkIwMUU4NTAiLCJ2aXNpdG9yX2lkIjoiNjYzNTkwMTAwMTU2NjEyMDAxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac580ceb67e34f46a9da10c3392b62aef0d710e63c9c87dcd740ef516109b60af2
hovercard-subject-tagissue:5439925069
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/157415/issue_layout
twitter:imagehttps://opengraph.githubassets.com/803bcbc12c64e667a1c39ee95681ddae09b1b201fce37333003c77e71ea69af7/python/cpython/issues/157415
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/803bcbc12c64e667a1c39ee95681ddae09b1b201fce37333003c77e71ea69af7/python/cpython/issues/157415
og:image:altI recently added a test in test_io.test_memoryio using _testcapi.set_nomemory() to inject a MemoryError: commit 23eda00. The test was flagged as "data race" by clang ThreadSanitizer on a GHA CI run...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamevstinner
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/157415#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F157415
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%2F157415
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/157415
Reloadhttps://github.com/python/cpython/issues/157415
Reloadhttps://github.com/python/cpython/issues/157415
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/157415
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/157415
Using _testcapi.set_nomemory() in a test triggers a ThreadSanitizer "data race"https://github.com/python/cpython/issues/157415#top
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issue-5439925069
23eda00https://github.com/python/cpython/commit/23eda007f8d543495ba4935df75d243d76f9ef7f
GHA CI runhttps://github.com/python/cpython/actions/runs/34737711156/job/103672505968?pr=157382
test_tracemalloc_track_race segfault on buildbot #143143 (comment)https://github.com/python/cpython/issues/143143#issuecomment-4081656148
tracemalloc aborts when run from threads in no-gil #126315 (comment)https://github.com/python/cpython/issues/126315#issuecomment-3048731039
gh-157415: Skip @support.nomemtest if Python is built with TSAN #157416https://github.com/python/cpython/pull/157416
gh-157415: Fix data race in pthread wrapper #157430https://github.com/python/cpython/pull/157430
[3.15] gh-157415: Fix data race in pthread wrapper (#157430) #159277https://github.com/python/cpython/pull/159277
[3.14] gh-157415: Fix data race in pthread wrapper (#157430) #159547https://github.com/python/cpython/pull/159547
vstinnerhttps://github.com/vstinner
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
on Sep 13, 2026https://github.com/python/cpython/issues/157415#event-31051429749
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653194057
#137994https://github.com/python/cpython/pull/137994
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653206343
gh-157416https://github.com/python/cpython/pull/157416
https://github.com/kumaraditya303
kumaraditya303https://github.com/kumaraditya303
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653232617
picnixzhttps://github.com/picnixz
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
on Sep 13, 2026https://github.com/python/cpython/issues/157415#event-31051917703
https://github.com/ngoldbaum
ngoldbaumhttps://github.com/ngoldbaum
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653578505
vstinnerhttps://github.com/vstinner
on Sep 13, 2026https://github.com/python/cpython/issues/157415#event-31053659470
gh-157415: Skip @support.nomemtest if Python is built with TSAN (#157416https://github.com/python/cpython/commit/e41677b08f2ded60572cd8baef4d719f7271ab6d
gh-157415https://github.com/python/cpython/issues/157415
#157416https://github.com/python/cpython/pull/157416
e41677bhttps://github.com/python/cpython/commit/e41677b08f2ded60572cd8baef4d719f7271ab6d
pythongh-157415: Fix data race in pthread wrapperhttps://github.com/vstinner/cpython/commit/250cf48f581e099bb805af93336129493a7428e4
pythongh-157415https://github.com/python/cpython/issues/157415
250cf48https://github.com/vstinner/cpython/commit/250cf48f581e099bb805af93336129493a7428e4
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653697224
@ngoldbaumhttps://github.com/ngoldbaum
gh-157430https://github.com/python/cpython/pull/157430
https://github.com/kumaraditya303
kumaraditya303https://github.com/kumaraditya303
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653730648
https://github.com/ngoldbaum
ngoldbaumhttps://github.com/ngoldbaum
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653799874
@vstinnerhttps://github.com/vstinner
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653846746
https://github.com/ngoldbaum
ngoldbaumhttps://github.com/ngoldbaum
on Sep 13, 2026https://github.com/python/cpython/issues/157415#issuecomment-5653859938
johnslavikhttps://github.com/johnslavik
on Sep 14, 2026https://github.com/python/cpython/issues/157415#event-31099063204
pythongh-157415: Skip @support.nomemtest if Python is built with TSAN (…https://github.com/johnslavik/cpython/commit/944384f6b9fa8a40230d727eda15a45a08487351
pythongh-157415https://github.com/python/cpython/issues/157415
…https://github.com/python/cpython/pull/157416
944384fhttps://github.com/johnslavik/cpython/commit/944384f6b9fa8a40230d727eda15a45a08487351
vstinnerhttps://github.com/vstinner
on Sep 17, 2026https://github.com/python/cpython/issues/157415#event-31327437135
gh-157415: Fix data race in pthread wrapper (#157430)https://github.com/python/cpython/commit/d1878ccb44999bfa30f5a0e84b4383e6068e5b72
gh-157415https://github.com/python/cpython/issues/157415
#157430https://github.com/python/cpython/pull/157430
d1878cchttps://github.com/python/cpython/commit/d1878ccb44999bfa30f5a0e84b4383e6068e5b72
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 17, 2026https://github.com/python/cpython/issues/157415#issuecomment-5716192729
gh-157430https://github.com/python/cpython/pull/157430
vstinnerhttps://github.com/vstinner
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Sep 17, 2026https://github.com/python/cpython/issues/157415#event-31327575420
vstinnerhttps://github.com/vstinner
on Oct 12, 2026https://github.com/python/cpython/issues/157415#event-33088249466
[3.15] gh-157415: Fix data race in pthread wrapper (#157430) (#159277)https://github.com/python/cpython/commit/18e0bcb85f9a93c0a500b4388cb5fabc59869569
gh-157415https://github.com/python/cpython/issues/157415
#157430https://github.com/python/cpython/pull/157430
#159277https://github.com/python/cpython/pull/159277
18e0bcbhttps://github.com/python/cpython/commit/18e0bcb85f9a93c0a500b4388cb5fabc59869569
[3.14] gh-157415: Fix data race in pthread wrapper (#157430) (#159547)https://github.com/python/cpython/commit/7c048824966c524ae7189eeec3de69c2be8ea8f3
gh-157415https://github.com/python/cpython/issues/157415
#157430https://github.com/python/cpython/pull/157430
#159547https://github.com/python/cpython/pull/159547
7c04882https://github.com/python/cpython/commit/7c048824966c524ae7189eeec3de69c2be8ea8f3
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Nov 17, 2026https://github.com/python/cpython/issues/157415#issuecomment-6934609746
#162144https://github.com/python/cpython/issues/162144
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/157415
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/157415
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%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.