-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyCode_GetCode
is not thread-safe and causes assertion fail with Python 3.13td
#127020
Comments
Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initialization and access thread-safe.
Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe.
Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe.
Thanks for the bug report @XuehaiPan. I think the linked PR should fix the crash. I verified it with the following command when running optree tests:
|
Thanks for the fix. I can confirm the unit test in #127043 fails on the main branch and passes with the patch in #127043. $ python3 -VV
Python 3.14.0a2+ experimental free-threading build (heads/main:c9b399fbdb0, Nov 20 2024, 15:18:27) [Clang 16.0.0 (clang-1600.0.26.4)]
$ python3 test_code.py
Assertion failed: (co->_co_cached->_co_code == NULL), function _PyCode_GetCode, file codeobject.c, line 1686.
[1] 37607 abort python3 test_code.py $ python3 -VV
Python 3.14.0a2+ experimental free-threading build (heads/pr/colesbury/127043:9242a83444c, Nov 20 2024, 15:13:34) [Clang 16.0.0 (clang-1600.0.26.4)]
$ python3 test_code.py
.
----------------------------------------------------------------------
Ran 1 test in 0.019s
OK |
…pythonGH-127043) Some fields in PyCodeObject are lazily initialized. Use atomics and critical sections to make their initializations and accesses thread-safe. (cherry picked from commit 3926842117feffe5d2c9727e1899bea5ae2adb28) Co-authored-by: Sam Gross <colesbury@gmail.com>
I guess it can be closed now? |
Crash report
What happened?
Race condition here:
cpython/Objects/codeobject.c
Lines 1663 to 1665 in 60403a5
Core dump and backtrace:
https://github.com/metaopt/optree/actions/runs/11913729282/job/33200071659#step:15:172
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.13.0 experimental free-threading build
Linked PRs
PyCode_GetCode
thread-safe for free threading #127043PyCode_GetCode
thread-safe for free threading (GH-127043) #127107The text was updated successfully, but these errors were encountered: