Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-102126: fix deadlock at shutdown when clearing thread states#102222
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
dd672a9 to 1e6a87bComparebedevere-bot commented Feb 24, 2023
🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit 1e6a87b 🤖 If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
ericsnowcurrently left a comment
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
There's one case that could be problematic but (ISTM) is highly unlikely: some other thread might call PyThreadState_Delete*() on one of the existing thread states, which would modify the linked list while we're walking it here. We could mitigate that (very small) risk by checking in those functions if the interpreter is finalizing and returning immediately (or blocking) if it is. FWIW, the status quo is already deficient in that case, and this PR only slightly adds to the problem. Regardless, the risk is fairly minimal so we can address that separately.
(Before merging, would you mind just double-checking that the risk actually is minimal? 😄)
One observation: the lock isn't strictly necessary here. It's needed for one of the following:
- in case a new thread state gets created for the interpreter
- in the case described above (
PyThreadState_Delete*()was called in another thread)
At this point in interpreter finalization, neither of those things should be happening. So it may make sense to disallow them (or ignore/block, in the case of the second one). Alternately we could give each interpreter it's own lock (e.g. PyInterpreterState.threads.mutex) to use when managing its thread states, as opposed to reusing the global "HEAD" lock like we currently do.
kumaraditya303 commented Feb 25, 2023
Yeah, I too noticed that but I am not concerned about that as at runtime shutdown such code is already unsafe and can crash or result in hang etc. Regardless I'll address that separately in a new issue and get this fixed first. Thanks for the review. |
kumaraditya303 commented Feb 25, 2023
The buildbots failures are unrelated so merging. https://buildbot.python.org/all/#/builders/259/builds/681/steps/5/logs/stdio |
miss-islington commented Feb 25, 2023
Thanks @kumaraditya303 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10, 3.11. |
miss-islington commented Feb 25, 2023
Sorry, @kumaraditya303, I could not cleanly backport this to |
miss-islington commented Feb 25, 2023
Sorry @kumaraditya303, I had trouble checking out the |
miss-islington commented Feb 25, 2023
Sorry, @kumaraditya303, I could not cleanly backport this to |
bedevere-bot commented Feb 25, 2023
GH-102234 is a backport of this pull request to the 3.11 branch. |
bedevere-bot commented Feb 25, 2023
GH-102235 is a backport of this pull request to the 3.10 branch. |
bedevere-bot commented Feb 25, 2023
GH-102236 is a backport of this pull request to the 3.9 branch. |
…states (pythonGH-102222). (cherry picked from commit 5f11478) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
… states (pythonGH-102222). (cherry picked from commit 5f11478) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
… states (pythonGH-102222). (cherry picked from commit 5f11478) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
kumaraditya303 commented Feb 25, 2023
|
bedevere-bot commented Mar 28, 2023
GH-102236 is a backport of this pull request to the 3.9 branch. |
…GH-102222) (#102236) (cherry picked from commit 5f11478)
… state… (python#102235) [3.10] pythonGH-102126: fix deadlock at shutdown when clearing thread states (pythonGH-102222). (cherry picked from commit 5f11478)
… state… (python#102235) [3.10] pythonGH-102126: fix deadlock at shutdown when clearing thread states (pythonGH-102222). (cherry picked from commit 5f11478)
Uh oh!
There was an error while loading. Please reload this page.