Uh oh!
There was an error while loading. Please reload this page.
gh-149816: #96 Fix a race condition in invoke_gc_callback with free threading - #150029
gh-149816: #96 Fix a race condition in invoke_gc_callback with free threading#150029dzaramelcone wants to merge 6 commits into
Conversation
encukou
commented
May 19, 2026
Could you add the test, since you already wrote it? It should be deterministic if it the bug if fixed, ritght? If it's resource-intensive, you can mark is with |
dzaramelcone
commented
May 20, 2026
Thank you for the review Petr! That test is flaky and relies on basically random permutations of thread ordering to reproduce it. however, now that I think of it, the original issue included a test that reliably reproduced the issue such that TSAN would flag it, so I will just include that one. |
dzaramelcone
commented
May 29, 2026
@encukou added! |
encukou
commented
Jun 1, 2026
Thank you! Did you consider |
dzaramelcone
commented
Jul 11, 2026
Hey Petr! Sorry for the delay. That looks like it should be fine to me, so I added the early return. Thank you for the review! Hope you are well! |
The optimization that avoided allocating an info dict when no gc callbacks were registered introduces a time of check to time of use race in free threaded mode (lineno 1943-1955). I just pulled out the check. Since info is always non-null, I also replaced XDECREF use with DECREF. (lineno 1959, lineno 1982).
I implemented a stress test for this and uncovered what I believe to be a bug with
_PyList_GetItemRef. I am following suit with python/cpython#149909 and not including the test with my PR for two reasons:_PyList_GetItemRef(but I'm happy to open an issue for it!)also, this is my first PR against CPython, I am doing it from PyCon US as part of the sprint! :) Hello world!