-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
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
base: main
Are you sure you want to change the base?
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 |
Objects/typeobject.c
Outdated
| #endif | ||
| type->tp_base = old_base; | ||
| #ifdef Py_GIL_DISABLED | ||
| types_start_world(); |
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.
these functions are no-op in gil enabled builds so ifdefs are not needed
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, |
| type->tp_base = old_base; | ||
| types_start_world(); | ||
| #ifdef Py_GIL_DISABLED | ||
| type_lock_allow_release(); |
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.
it would be better to add an empty macro for type_lock_allow_release similar to how it is done for types_start_world in gil-enabled build then you won't these ifdefs
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.