Skip to content

[3.12] gh-119585: Fix crash involving PyGILState_Release() and PyThreadState_Clear() (GH-119753) #119861

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

Merged
merged 1 commit into from
May 31, 2024

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented May 31, 2024

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)

…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]>
@colesbury colesbury requested a review from DinoV May 31, 2024 15:07
@colesbury colesbury enabled auto-merge (squash) May 31, 2024 15:10
@colesbury colesbury merged commit 738cf21 into python:3.12 May 31, 2024
28 checks passed
@colesbury colesbury deleted the backport-bcc1be3-3.12 branch May 31, 2024 16:07
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.

1 participant