You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Data races in typeobject.c for type structure updates #133467
I'm interested in the free-threading topic and want to try the 'tp_base and tp_bases are assigned in likely unsafe ways' subtask.
I don't have specific instructions for that but here are some general thoughts. Inside typeobject.c, look at places where ->tp_base and ->tp_bases get assigned. If they are inside a function that has ASSERT_NEW_TYPE_OR_LOCKED then those should be safe. If not, you need to follow the logic to see how those functions get called. If those assignments happen after the type has been potentially revealed to other threads then the assignment is likely a data race. Possible fix would be to stop-the-world, do the assignment and then start the world again. Note that while the world is stopped, it is not safe to call most of the Python APIs. That's the reason for the complex logic related to apply_type_slot_updates(). I'm not sure but I suspect change base or bases could require similar levels of care.
I'm interested in the free-threading topic and want to try the 'tp_base and tp_bases are assigned in likely unsafe ways' subtask.
I don't have specific instructions for that but here are some general thoughts. Inside typeobject.c, look at places where ->tp_base and ->tp_bases get assigned. If they are inside a function that has ASSERT_NEW_TYPE_OR_LOCKED then those should be safe. If not, you need to follow the logic to see how those functions get called. If those assignments happen after the type has been potentially revealed to other threads then the assignment is likely a data race. Possible fix would be to stop-the-world, do the assignment and then start the world again. Note that while the world is stopped, it is not safe to call most of the Python APIs. That's the reason for the complex logic related to apply_type_slot_updates(). I'm not sure but I suspect change base or bases could require similar levels of care.
Thanks very much for your instructions! ❤ It helps me a lot and guides the way!
I will try to construct the data race case and update if I have any new findings.
Activity
Merge branch 'main' into pythongh-133467-typeobject-tsan-suppress
gh-133467: Add TSAN suppressions for races in typeobject (gh-133534)
pythongh-133467: Add TSAN suppressions for races in typeobject (pytho…
[3.14] gh-133467: Add TSAN suppressions for races in typeobject (gh-1…
pythongh-133467: Add TSAN suppressions for races in typeobject (pytho…
gh-133467: fix data race in `type_set_name` (#137302)
pythongh-133467: fix data race in `type_set_name` (pythonGH-137302)
pythongh-133467: Add TSAN suppressions for races in typeobject (pytho…
pythongh-133467: fix data race in `type_set_name` (python#137302)
[3.14] gh-133467: fix data race in `type_set_name` (GH-137302) (#137303)
LindaSummer commentedon Oct 14, 2025
Hi @nascheme ,
I'm interested in the free-threading topic and want to try the 'tp_base and tp_bases are assigned in likely unsafe ways' subtask. 😊
Best Regards,
Edward
nascheme commentedon Oct 15, 2025
I don't have specific instructions for that but here are some general thoughts. Inside typeobject.c, look at places where
->tp_baseand->tp_basesget assigned. If they are inside a function that hasASSERT_NEW_TYPE_OR_LOCKEDthen those should be safe. If not, you need to follow the logic to see how those functions get called. If those assignments happen after the type has been potentially revealed to other threads then the assignment is likely a data race. Possible fix would be to stop-the-world, do the assignment and then start the world again. Note that while the world is stopped, it is not safe to call most of the Python APIs. That's the reason for the complex logic related toapply_type_slot_updates(). I'm not sure but I suspect change base or bases could require similar levels of care.LindaSummer commentedon Oct 16, 2025
Hi @nascheme ,
Thanks very much for your instructions! ❤ It helps me a lot and guides the way!
I will try to construct the data race case and update if I have any new findings.
Best Regards,
Edward
gh-133467: Fix typeobject `tp_base` race in free threading (gh-140549)
kumaraditya303 commentedon Nov 12, 2025
Closing as all the races are fixed.
pythongh-133467: Fix typeobject `tp_base` race in free threading (pyt…