-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
_Py_SetImmortal
must be run on allocating thread (no-gil)
#113956
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
Comments
A few thoughts:
|
I would be hesitant to add an assertion to The only call I've seen that concerns me is in |
@colesbury thanks for the reply. This makes sense. I had thought this is more externally reachable. I think you could make it concurrency safe by borrowing a third bit from |
Yeah, that would address concurrency safety, but using
|
Bug report
Bug description:
The code in
_Py_SetImmortal
must be run on the thread that originally allocated the object. If this is not the case, then a race betweenPy_INCREF
can cause the_Py_SetImmortal
to be ignored.cpython/Include/internal/pycore_object.h
Lines 128 to 139 in 2e7577b
Example sequence:
_Py_Incref
.ob_ref_local
, and calculates new value._Py_SetImmortal
.ob_ref_local
, and unsets the value from immortal.In the nogil fork, there is some defensive code on other operations that need to be run on the allocating thread, e.g.
https://github.com/colesbury/nogil-3.12/blob/cedde4f5ec3759ad723c89d44738776f362df564/Include/internal/pycore_object.h#L361C19-L361C19
I think something like this should occur inside
_Py_SetImmortal
.It looks like
_Py_SetImmortal
is not exposed outside the runtime. However, PEP 683, says:This implies there is an intent to expose it, and with the changes to nogil. It seems that this should be exposed as an explicit operation, rather than by setting the ref count directly.
CC @ericsnowcurrently @colesbury
P.S. I am happy to PR any required changes.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
The text was updated successfully, but these errors were encountered: