GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.14] gh-143650: Fix importlib race condition on import failure (GH-143651) by miss-islington · Pull Request #144662 · python/cpython

Conversation

@miss-islington

@miss-islington miss-islington commented Feb 10, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fix a race condition where a thread could receive a partially-initialized
module when another thread's import fails. The race occurs when:

  1. Thread 1 starts importing, adds module to sys.modules
  2. Thread 2 sees the module in sys.modules via the fast path
  3. Thread 1's import fails, removes module from sys.modules
  4. Thread 2 returns a stale module reference not in sys.modules

The fix adds verification after the "skip lock" optimization in both Python
and C code paths to check if the module is still in sys.modules. If the
module was removed (due to import failure), we retry the import so the
caller receives the actual exception from the import failure rather than
a stale module reference.
(cherry picked from commit ac8b5b6)

Co-authored-by: Gregory P. Smith [email protected]
Co-Authored-By: Claude Opus 4.5 [email protected]

  • Issue: importlib race condition allows stale module ref to escape on failure #143650

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gpshead @claude @miss-islington
pythongh-143650: Fix importlib race condition on import failure (pyth…
6cc1f0c
…onGH-143651)

Fix a race condition where a thread could receive a partially-initialized
module when another thread's import fails. The race occurs when:

1. Thread 1 starts importing, adds module to sys.modules
2. Thread 2 sees the module in sys.modules via the fast path
3. Thread 1's import fails, removes module from sys.modules
4. Thread 2 returns a stale module reference not in sys.modules

The fix adds verification after the "skip lock" optimization in both Python
and C code paths to check if the module is still in sys.modules. If the
module was removed (due to import failure), we retry the import so the
caller receives the actual exception from the import failure rather than
a stale module reference.
(cherry picked from commit ac8b5b6)

Co-authored-by: Gregory P. Smith <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
@miss-islington
miss-islington requested review from brettcannon, ericsnowcurrently, kumaraditya303, ncoghlan and warsaw as code owners February 10, 2026 13:08
@bedevere-app bedevere-app Bot added the awaiting review label Feb 10, 2026
This was referenced Feb 10, 2026
importlib race condition allows stale module ref to escape on failure #143650
Closed
gh-143650: Fix importlib race condition on import failure #143651
Merged
@brettcannon
brettcannon requested review from gpshead and removed request for brettcannon February 11, 2026 00:12
gpshead
gpshead approved these changes Feb 11, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Feb 11, 2026
@gpshead
gpshead enabled auto-merge (squash) February 11, 2026 06:06
@gpshead
gpshead merged commit 7d07470 into python:3.14 Feb 11, 2026
53 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 11, 2026
@miss-islington
miss-islington deleted the backport-ac8b5b6-3.14 branch February 11, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead approved these changes
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@miss-islington @gpshead
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.