Skip to content
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

Linux: Fix a rare crash that could occur when shutting down an interpreter running multiple threads #324

Merged
merged 6 commits into from Oct 30, 2022

Conversation

jamadden
Copy link
Contributor

when some of those threads are in greenlets making calls to functions that release the GIL.

When Python notices that the thread would like to obtain the GIL again, but the interpreter is exiting, it calls pthread_exit. With GCC/libstdc++ at least, this ultimately "raises" what is meant to be an uncatchable exception in order to cause the stack to unwind and destructors to run. But if a noexcept function is in the call stack, then attempting to unwind through that function (with this uncatchable exception in place) would trigger the runtime to think that we had violated our dynamic exception specification, and call std::terminate() — so even though the program had otherwise exited cleanly, this one background thread was ruining it for everyone.

The solution is to be more careful with our noexcept functions.

Interestingly, the situation with the windows C/C++ runtime is exactly opposite.

Turns out on Linux with gcc and libstdc++ calling pthread_exit() raises an uncatchable exception. That is called when reacquiring the GIL in a background thread if the main thread has terminated. The use of G_NOEXCEPT in that code path was resulting in the C++ runtime calling std::terminate when that happened.
…to force the termination that we otheriwse can't seem to get.
python3.5 is long EOL'd.
@jamadden jamadden merged commit 23f9123 into master Oct 30, 2022
@jamadden jamadden deleted the noexcept-crashing-on-linux branch October 30, 2022 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant