Uh oh!
There was an error while loading. Please reload this page.
gh-133467: Fix typeobject tp_base race in free threading - #140549
Conversation
tp_base race in free threading in typeobjecttp_base race in free threadingLindaSummer
commented
Oct 24, 2025
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
0df5ffaComparetp_base race in free threadingtp_base race in free threadingtp_base race in free threadingtp_base race in free threadingLindaSummer
commented
Oct 29, 2025
Hi @nascheme and @colesbury , Sorry to bother you. 😊 Hope to get suggestions from you! Best Regards, |
nascheme
commented
Oct 29, 2025
LGTM. Using |
colesbury
commented
Oct 29, 2025
via email
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:
***@***.***>
|
nascheme
commented
Oct 29, 2025
We have this code in |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
f494440 to
9836fd7CompareLindaSummer
commented
Nov 3, 2025
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, |
colesbury
commented
Nov 3, 2025
You'll need to update the calls to use Also, please remove the associated suppression in Tools/tsan/suppressions_free_threading.txt |
073f989 to
a20ca83CompareLindaSummer
commented
Nov 4, 2025
Hi @colesbury , Thanks very much for your help and suggestion! 😊 I have added the Please correct me if I misunderstand. Best Regards, |
Uh oh!
There was an error while loading. Please reload this page.
a20ca83 to
3b85c9eCompareUh oh!
There was an error while loading. Please reload this page.
LindaSummer
commented
Nov 5, 2025
Hi @nascheme , @colesbury and @kumaraditya303 , Thanks very much for your patience and kind suggestions! 😊 Wish you a good day! Best Regards, |
Uh oh!
There was an error while loading. Please reload this page.
cd33709 to
95532d7CompareUh oh!
There was an error while loading. Please reload this page.
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: |
nascheme
commented
Nov 7, 2025
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? |
Please don't forget about backporting or remove the "needs backport to 3.14" label if backporting is not planned. |
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.