-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
gh-133467: Fix typeobject tp_base race in free threading
#140549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tp_base race in free threading in typeobjecttp_base race in free threading
|
Hi @nascheme, Thansk very much for your guidance. 😊 I have created a case for the race of Please help take a look. Best Regards, |
ba3206e to
0df5ffa
Compare
tp_base race in free threadingtp_base race in free threading
tp_base race in free threadingtp_base race in free threading
|
Hi @nascheme and @colesbury , Sorry to bother you. 😊 Hope to get suggestions from you! Best Regards, |
|
LGTM. Using |
|
I think we might need the helper that avoids releasing the critical section
here. I think it might not be safe otherwise
…On Wed, Oct 29, 2025 at 1:01 PM Neil Schemenauer ***@***.***> wrote:
*nascheme* left a comment (python/cpython#140549)
<#140549 (comment)>
LGTM. Using types_stop_world() and types_start_world() would be a little
cleaner, IMHO but that's minor.
—
Reply to this email directly, view it on GitHub
<#140549 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFAD6VCRC3T5PAJC5UUTB332DXGJAVCNFSM6AAAAACKDZLQCOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTINRSG4YDAMZQG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
We have this code in |
f494440 to
9836fd7
Compare
|
Hi @nascheme , @colesbury and @kumaraditya303 , I have updated the PR as suggested in the review comment. 😄 Please help take a review. Wish you a good day! Best Regards, |
|
You'll need to update the calls to use Also, please remove the associated suppression in Tools/tsan/suppressions_free_threading.txt |
073f989 to
a20ca83
Compare
Hi @colesbury , Thanks very much for your help and suggestion! 😊 I have added the Please correct me if I misunderstand. Best Regards, |
a20ca83 to
3b85c9e
Compare
Misc/NEWS.d/next/Core_and_Builtins/2025-10-24-14-29-12.gh-issue-133467.A5d6TM.rst
Outdated
Show resolved
Hide resolved
|
Hi @nascheme , @colesbury and @kumaraditya303 , Thanks very much for your patience and kind suggestions! 😊 Wish you a good day! Best Regards, |
cd33709 to
95532d7
Compare
colesbury
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
|
Thanks @LindaSummer for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Sorry, @LindaSummer and @colesbury, I could not cleanly backport this to |
|
Backport probably depends on backporting: |
|
Yes, this needs gh-133177 to be backported too and that's a pretty complicated change. So, it feels a bit risky to backport. My guess is that these races would be quite rare in real Python code. It's rare that Python code mutates types in ways that trigger these races. Maybe wait a bit more? |
Issue
#133467
Proposed Changes
PyTypeObject::tp_basebetween typemember__base__and set of__bases__.Comment
Root cause
Since the
__bases__'s getter and setter are protetcted byTYPE_LOCK.cpython/Objects/typeobject.c
Line 1916 in 289360a
cpython/Objects/typeobject.c
Lines 586 to 596 in 289360a
So it is safe for concurrency.
But the update of bases will re-evaluate the
tp_baseagain and would be in race with the direct access of__base__.cpython/Objects/typeobject.c
Line 1459 in 289360a
How to fix
At the beginning I try to use the
TYPE_LOCKto protect thetb_basefor__base__access.But it's a directly memory access by offset and I have no more idea except StopTheWorld.
So I add a STW for the updating of
tp_basein setter.Please let me know if we have a better way for it. 😊
TSAN output for this race
Here is the TSAN core output of this race.