Skip to content

gh-146270: Fix PyMember_SetOne(..., NULL) not being atomic - #148800

Merged
colesbury merged 6 commits into
python:mainfrom
dpdani:gh/146270-fix-slot-del-atomic
May 6, 2026
Merged

gh-146270: Fix PyMember_SetOne(..., NULL) not being atomic#148800
colesbury merged 6 commits into
python:mainfrom
dpdani:gh/146270-fix-slot-del-atomic

Conversation

@dpdani

@dpdanidpdani commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a sequential consistency bug (introduced by yours truly) whereby two threads that are deleting a struct member may observe both their deletions to be successful.

In order to test this properly, I couldn't use threading.Barrier because its overhead was enough to mask the bug, making the test flaky. Therefore, a spinning-loop barrier was added in the _testcapi module.

Comment threadPython/structmember.c Outdated
Comment threadPython/structmember.c
Comment threadLib/test/test_free_threading/test_slots.py
Comment threadModules/_testcapimodule.c Outdated
@colesbury

Copy link
Copy Markdown
Contributor

Thanks for fixing this! I left some comments above.

I think it's worth prioritizing keeping the tests fast. In general, it helps to keep them small and understandable too.

@dpdani
dpdani requested a review from colesburyApril 27, 2026 14:15
@colesbury
colesbury merged commit 1bdfc0f into python:mainMay 6, 2026
58 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @dpdani for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@bedevere-app

Copy link
Copy Markdown

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

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label May 6, 2026
@dpdani
dpdani deleted the gh/146270-fix-slot-del-atomic branch May 6, 2026 13:53
colesbury pushed a commit that referenced this pull request May 6, 2026
…h-148800) (#149460)
Fixes a sequential consistency bug whereby two threads that are deleting a struct member may observe both their deletions to be successful.
(cherry picked from commit 1bdfc0f)
Co-authored-by: Daniele Parmeggiani <8658291+dpdani@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@dpdani@colesbury@x42005e1f