-
Notifications
You must be signed in to change notification settings - Fork 22.9k
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
PyEval_AcquireThread can crash process if called from another thread at interpreter shutdown #117762
Comments
Relevant information from python/cpython#110490 Would it be possible to use the following as a guard? It seems to be set before PyThreadState *tstate = PyThreadState_GET();
if (tstate->interp->finalizing){
...
} |
I don't think so, error: member access into incomplete type 'PyInterpreterState' (aka '_is')
printf("\033[32m%s:%d PyEval_AcquireThread IsFinalizing=%d tstate->interp->finalizing=%d \033[0m\n", __FILE__, __LINE__, _Py_IsFinalizing(), tstate->interp->finalizing); I mean, I could try hacking something together here cause I have the address of the
It still doesn't seem to work here:
I even attempted wrapping To be clear, the backtrace for the Python interpreter thread in the coredump indicates
Edit: Oh, but this probably makes sense. I just looked at the exact version of Python I'm using. 3.10 doesn't have
|
I think we tried to patch this in CPython on pybind11, alas we had trouble getting it merged: python/cpython#28525 |
Would a solution on our end here be to mimick exactly for each version of cpython the function that checks if the gil acquisition will terminate (https://github.com/python/cpython/blob/main/Python/pystate.c#L2749 in the latest version for example and https://github.com/python/cpython/blob/3.10/Python/ceval_gil.h#L204 for 3.10) and use that to guard calling the gil acquisition? There is still the possibility of a race if the finalization starts in between our check and the gil acquisition (that would need the cpython PR above to solve). I'm not very optimistic it will solve @peterdelevoryas issue though as in 3.10, we only have the one flag which we already guard on. So we are in a case where we're hitting exactly this worst case scenario where the cleanup early in the finalization triggers the thread to destroy objects which is very likely to race with the flag being set just after. |
🐛 Describe the bug
Meta xref: https://fb.workplace.com/groups/1405155842844877/posts/7910584775635252/?comment_id=7912862145407515&reply_comment_id=7917182454975484¬if_id=1705598818428473¬if_t=work_group_comment_mention
Quote:
Versions
main
cc @albanD
The text was updated successfully, but these errors were encountered: