-
-
Notifications
You must be signed in to change notification settings - Fork 30.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
Segfault in _PyTrash_begin when faulthandler tries to dump thread stacks #88615
Comments
I am using Python 3.9.4 on CentOS 7. faulthandler is registered with SIGUSR1: faulthandler.register(signal.SIGUSR1) Sending SIGUSR1 normally correctly dumps the thread stacks, but occasionally it segfaults from the main thread instead: Thread 1 (Thread 0x7efe15e69740 (LWP 15201)): It has failed because tstate is null. tstate came from Py_TRASHCAN_BEGIN_CONDITION that calls PyThreadState_GET(), assuming it returns a valid pointer, but the comment on the _PyThreadState_GET macro says: Efficient macro reading directly the 'gilstate.tstate_current' atomic The only place I can see that tstate_current would be set to NULL is in _PyThreadState_DeleteCurrent(). I suspect that there has been a race with a thread exit. I'm not sure quite what to do about this. Perhaps faulthandler should check if tstate_current is NULL and set it suitably if so? |
_Py_DumpTracebackThreads() should not use Py_DECREF(). It's a bug. It must only *read* memory, not *modify* memory since it's called from a signal handler. It's a regression in dump_traceback(). Python 3.9 and 3.10 use: frame = PyThreadState_GetFrame(tstate);
...
Py_DECREF(frame); The main branch (future 3.11) uses: frame = tstate->frame; Without Py_DECREF(): it's a borrowed reference. It was changed by commit ae0a2b7. Python 3.9 and 3.10 should be fixed to use a borrowed reference. |
The bug should now be fixed in 3.9 and 3.10 branches. The main branch should not be impacted, it has a different implementation. Thanks for the bug report Duncan Grisby. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: