-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
gh-119585: Fix crash involving PyGILState_Release()
and PyThreadState_Clear()
#119753
Conversation
…readState_Clear()` Don't decrement `gilstate_counter` in `PyGILState_Release()` until after `PyThreadState_Clear()` is called. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and PyGILState_Release()` and if `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed.
Make them more similar to our patterns with refcounts around finalizers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
…readState_Clear()` (pythonGH-119753) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash. (cherry picked from commit bcc1be3) Co-authored-by: Sam Gross <[email protected]>
Sorry, @colesbury, I could not cleanly backport this to
|
GH-119859 is a backport of this pull request to the 3.13 branch. |
…d `PyThreadState_Clear()` (pythonGH-119753) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash. (cherry picked from commit bcc1be3) Co-authored-by: Sam Gross <[email protected]>
…d `PyThreadState_Clear()` (pythonGH-119753) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash. (cherry picked from commit bcc1be3) Co-authored-by: Sam Gross <[email protected]>
GH-119861 is a backport of this pull request to the 3.12 branch. |
…hreadState_Clear()` (GH-119753) (#119859) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash. (cherry picked from commit bcc1be3) Co-authored-by: Sam Gross <[email protected]>
…hreadState_Clear()` (GH-119753) (#119861) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash. (cherry picked from commit bcc1be3)
…readState_Clear()` (python#119753) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash.
…readState_Clear()` (python#119753) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash.
Make sure that
gilstate_counter
is not zero in when callingPyThreadState_Clear()
. A destructor called fromPyThreadState_Clear()
may call back intoPyGILState_Ensure()
andPyGILState_Release()
. Ifgilstate_counter
is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash.