FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-143650: Fix importlib race condition on import failure (GH-143651) by miss-islington · Pull Request #144662 · python/cpython · GitHub

Repository navigation

[3.14] gh-143650: Fix importlib race condition on import failure (GH-143651) - #144662

Merged
gpshead merged 1 commit into
python:3.14from
miss-islington:backport-ac8b5b6-3.14
Feb 11, 2026
Merged

gpshead merged 1 commit into
python:3.14from
miss-islington:backport-ac8b5b6-3.14

Conversation

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

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 68491+gpshead@users.noreply.github.com
Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

…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 <68491+gpshead@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
gpshead enabled auto-merge (squash) February 11, 2026 06:06
gpshead merged commit 7d07470 into python:3.14 Feb 11, 2026
53 checks passed
miss-islington deleted the backport-ac8b5b6-3.14 branch February 11, 2026 06:06
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL