-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
faulthandler
itself crashes in free-threading build (in _Py_DumpExtensionModules
)
#120837
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Comments
colesbury
added
type-bug
An unexpected behavior, bug, or error
3.13
bugs and security fixes
topic-free-threading
3.14
new features, bugs and security fixes
labels
Jun 21, 2024
corona10
added a commit
to corona10/cpython
that referenced
this issue
Jun 26, 2024
corona10
added a commit
that referenced
this issue
Jun 27, 2024
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Jun 27, 2024
…afe (pythongh-121051) (cherry picked from commit 1a2e7a7) Co-authored-by: Donghee Na <[email protected]>
mrahtz
pushed a commit
to mrahtz/cpython
that referenced
this issue
Jun 30, 2024
noahbkim
pushed a commit
to hudson-trading/cpython
that referenced
this issue
Jul 11, 2024
estyxx
pushed a commit
to estyxx/cpython
that referenced
this issue
Jul 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Bug report
The
faulthandler
module can dump Python tracebacks when a crash occurs. Unfortunately, the current implementation itself crashes in the free-threaded build. This is mostly undetected because our tests expect a crash, but faulthandler itself crashing is not desirable.Faulthandler may be called without a valid thread state (i.e., without holding GIL)
Faulthandler may be triggered when the thread doesn't have a valid thread state (i.e., doesn't hold the GIL in the default build and is not "attached" in the free-threaded build). Additionally, it's called from a signal handler, so we only want to call async-signal-safe functions (generally no locking).
Faulthandler calls
PyDict_Next
(via_Py_DumpExtensionModules
) on the modules dictionary. This is not entirely safe in the default build (because we don't hold the GIL), but works well enough in practice.However, it will consistently crash in the free-threaded build because
PyDict_Next
starts a critical section, which assumes there is a valid thread state.Suggestion:
_PyDict_Next()
, which doesn't internally lock the dict_PyDict_Next()
loop, with_PyMutex_LockTimed
timeout=0
. If we can't immediately lock the dict, we should not dump modules. This async-signal-safe because it's just a simple compare-exchange and doesn't block.PyMutex_Unlock()
because it's not async-signal-safe (it internally acquires locks in order to wake up threads), so we should either use a simple atomic exchange to unlock the dict (without waking up waiters) or not bother unlocking the lock at all. We exit shortly after_Py_DumpExtensionModules
, so it doesn't matter if we don't wake up other threads.Linked PRs
The text was updated successfully, but these errors were encountered: