Skip to content

gh-162144: Skip @nomemtest tests when using a thread sanitizer (TSan) - #162154

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:nomemtest_tsan
Nov 17, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:nomemtest_tsan

Conversation

@vstinner

@vstinner vstinner commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Am I correct that this should be fixed in _testcapi?

@vstinner

Copy link
Copy Markdown
Member Author

Am I correct that this should be fixed in _testcapi?

The root issue is that PyMem_SetAllocator() uses a lock to set an allocator, whereas allocator functions such as PyMem_RawMalloc() , PyMem_Malloc() and PyObject_Malloc() get the allocator without lock. Adding a lock would make Python memory allocators slower, whereas the issue only occurs when using tracemalloc.start() and _testcapi functions (to inject MemoryError).

_testcapi only exposes functions which can be used to trigger the data race.

@vstinner
vstinner merged commit e28063e into python:main Nov 17, 2026
64 checks passed
@vstinner
vstinner deleted the nomemtest_tsan branch November 17, 2026 20:48
@miss-islington-app

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 17, 2026

Copy link
Copy Markdown

GH-162174 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 17, 2026
@bedevere-app

bedevere-app Bot commented Nov 17, 2026

Copy link
Copy Markdown

GH-162175 is a backport of this pull request to the 3.14 branch.

@vstinner

Copy link
Copy Markdown
Member Author

Merged. Thanks for the review @sobolevn.

vstinner added a commit that referenced this pull request Nov 17, 2026
…er (TSan) (GH-162154) (#162174)

gh-162144: Skip `@nomemtest` tests when using a thread sanitizer (TSan) (GH-162154)
(cherry picked from commit e28063e)

Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Nov 17, 2026
…er (TSan) (GH-162154) (#162175)

gh-162144: Skip `@nomemtest` tests when using a thread sanitizer (TSan) (GH-162154)
(cherry picked from commit e28063e)

Co-authored-by: Victor Stinner <vstinner@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants