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
Read and write of __class__ in two threads causes crash #120198
FTR, I got a crash with a print(1) in the audit hook and only 1000 runs and 4 threads (not a constant crash but still with the same error). I'll investigate on my side.
@Zheaoli it might not be a threading issue. I wrapped the function you sent with _PyEval_StopTheWorld(is);_PyEval_StartTheWorld(is); and it still crashes. Usually that's strong enough to prevent any races, so I'm thinking the threads might be exposing something else.
BTW, I checked the object_set_class code and couldn't find any issues there. This is where it's calling the audit hooks.
I only see a test failure on a single macOS nogil buildbot, and all the rest are fine? And I'd expect this new test to expose threading issues, because that's what it's for.
The fix has certainly not introduced a reference leak, so if anything is going to get reverted, it should just be the test.
I just fixed the problem on free threading, so the problem is gone.
The refleak buildbot was failing not because of an actual refleak but it ran the test long enough to always segfault. So I fixed it on the free threading buildbot as well.
Activity
Eclips4 commentedon Jun 7, 2024
Is this a free threaded build?
Fidget-Spinner commentedon Jun 7, 2024
Both builds (default and free-threaded).
Fidget-Spinner commentedon Jun 7, 2024
FWIW I cannot repro locally on my own machine, but it crashes the CI.
Eclips4 commentedon Jun 7, 2024
If I run this code, no crash occurs:
But if I apply your changes from the #120195 and run
test_free_threading.test_typeit will crash:Fidget-Spinner commentedon Jun 7, 2024
Oh yeah I get it only in the test too. Thanks!
Fidget-Spinner commentedon Jun 7, 2024
Well I'm not sure how to fix this. So it's up for grabs for anyone to take!
Zheaoli commentedon Jun 8, 2024
I can reproduce on Linux/x86_64, would you mind I take a try?
Fidget-Spinner commentedon Jun 8, 2024
@Zheaoli Yeah sure go ahead!
Zheaoli commentedon Jun 8, 2024
Seems the bugs root cause here https://github.com/python/cpython/blob/main/Lib/test/libregrtest/setup.py#L73-L77
Can reproduced by the code following below
Let me find more detail about the race condition here
Zheaoli commentedon Jun 8, 2024
This bug is also in Python 3.9 ~ now
Zheaoli commentedon Jun 9, 2024
Update status:
I may need some help here.
For now, I have observed some interesting detail
I think this is a race condition issue for the sys_audit. But I may need some help to dive deeper into this issue...
cc @zooba for #12613
picnixz commentedon Jun 9, 2024
FTR, I got a crash with a
print(1)in the audit hook and only 1000 runs and 4 threads (not a constant crash but still with the same error). I'll investigate on my side.Fidget-Spinner commentedon Jun 9, 2024
@Zheaoli it might not be a threading issue. I wrapped the function you sent with
_PyEval_StopTheWorld(is);_PyEval_StartTheWorld(is);and it still crashes. Usually that's strong enough to prevent any races, so I'm thinking the threads might be exposing something else.BTW, I checked the
object_set_classcode and couldn't find any issues there. This is where it's calling the audit hooks.cpython/Objects/typeobject.c
Line 6540 in 34f5ae6
Zheaoli commentedon Jun 9, 2024
Yep, https://github.com/python/cpython/blob/main/Python/sysmodule.c#L282 the crash because of here...
3 remaining items
pythongh-120198: Fix race condition when editing __class__ with an au…
gh-120198: Fix race condition when editing __class__ with an audit ho…
encukou commentedon Jun 12, 2024
It seems that this started a reference leak on the 3.13 buildbots, see e.g. https://buildbot.python.org/all/#/builders/1396/builds/138
gh-120198: Fix race condition when editing __class__ with an audit ho…
zooba commentedon Jun 12, 2024
I only see a test failure on a single macOS nogil buildbot, and all the rest are fine? And I'd expect this new test to expose threading issues, because that's what it's for.
The fix has certainly not introduced a reference leak, so if anything is going to get reverted, it should just be the test.
Fidget-Spinner commentedon Jun 12, 2024
I just fixed the problem on free threading, so the problem is gone.
The refleak buildbot was failing not because of an actual refleak but it ran the test long enough to always segfault. So I fixed it on the free threading buildbot as well.
pythongh-120198: Fix race condition when editing __class__ with an au…
gh-120198: Stop the world when setting __class__ on free-threaded bui…
pythongh-120198: Stop the world when setting __class__ on free-thread…
pythongh-120198: Fix race condition when editing __class__ with an au…
pythongh-120198: Stop the world when setting __class__ on free-thread…
[3.13] gh-120198: Stop the world when setting __class__ on free-threa…
pythongh-120198: Fix race condition when editing __class__ with an au…
pythongh-120198: Stop the world when setting __class__ on free-thread…