gh-153176: Fix crash in _PyMem_mi_page_reclaimed on free-threaded debug builds#153307
Open
zangjiucheng wants to merge 1 commit into
Open
gh-153176: Fix crash in _PyMem_mi_page_reclaimed on free-threaded debug builds#153307zangjiucheng wants to merge 1 commit into
zangjiucheng wants to merge 1 commit into
Conversation
Contributor
|
I also think we can just relax this assertion. Thanks for your fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #153176.
On free-threaded debug builds, destroying a subinterpreter could abort the
process with:
_PyMem_mi_page_reclaimed()asserted that the page being reclaimed alwaysbelongs to the current thread state. That assumption doesn't hold during
stop-the-world events (e.g. subinterpreter teardown), where a page can be
reclaimed on behalf of a different thread state than the one currently
running. The function already looks up the correct owning thread state via
tstate_from_heap(mi_page_heap(page))— it just also asserted, incorrectly,that this always equals the current thread state. This mirrors the reasoning
in
_PyMem_mi_page_maybe_free(), which does not make the same assumption.This removes the overly-restrictive assertion and adds a regression test
that reproduces the crash via
_testinternalcapi.create_interpreter()/destroy_interpreter(), run in a subprocess so a regression fails the testinstead of aborting the whole test runner.
Test plan
./python -m test test_free_threading.test_interpreters -vmainprior to the fix; confirmed it nolonger reproduces with this change on a free-threaded debug build.