Skip to content

gh-149816: #96 Fix a race condition in invoke_gc_callback with free threading#150029

Draft
dzaramelcone wants to merge 1 commit into
python:mainfrom
dzaramelcone:gh-149816-96
Draft

gh-149816: #96 Fix a race condition in invoke_gc_callback with free threading#150029
dzaramelcone wants to merge 1 commit into
python:mainfrom
dzaramelcone:gh-149816-96

Conversation

@dzaramelcone
Copy link
Copy Markdown

@dzaramelcone dzaramelcone commented May 18, 2026

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:

  1. My implementation was resource intensive and not deterministic.
  2. I didn't want to scope creep fixing the bug with _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!

@python-cla-bot
Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

@bedevere-app bedevere-app Bot mentioned this pull request May 18, 2026
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant