gh-153797: Fix possible crash when re-importing extension modules after OOM - #153798
Open
lpyu001 wants to merge 1 commit into
Open
gh-153797: Fix possible crash when re-importing extension modules after OOM#153798lpyu001 wants to merge 1 commit into
lpyu001 wants to merge 1 commit into
Conversation
Fix a crash that could occur after an out-of-memory error when re-importing an extension module.
lpyu001
requested review from
FFY00,
brettcannon,
ericsnowcurrently,
kumaraditya303,
ncoghlan and
warsaw
as code owners
July 16, 2026 02:52
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.
When _modules_by_index_set() fails while re-importing a legacy single-phase extension module, it may leave a MemoryError pending. The cleanup path previously called PyMapping_DelItem() with that exception still set, causing debug builds to abort when the deletion succeeded.
Use the existing remove_module() helper to preserve the original exception while removing the partially initialized module from sys.modules. This keeps the cleanup consistent with other import failure paths and prevents the interpreter crash.
MemoryErrortrips_Py_CheckSlotResultinreload_singlephase_extension#153797