Skip to content

gh-126929: Retry extension loading with long Windows paths - #156759

Open
Solaris-star wants to merge 1 commit into
python:mainfrom
Solaris-star:fix-gh-126929-long-path-dll-load
Open

Solaris-star wants to merge 1 commit into
python:mainfrom
Solaris-star:fix-gh-126929-long-path-dll-load

Conversation

@Solaris-star

@Solaris-star Solaris-star commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #126929.

On Windows, retry extension-module loading with a long-path-compatible DLL path when the initial load fails because the path exceeds legacy limits.

The change also adds the required Windows NEWS entry.

Validation performed:

  • git diff --check
  • tracked-secret scan on both changed files
  • commit contains DCO sign-off and an SSH signature

Windows-specific runtime validation was not available locally.

Signed-off-by: Solaris-star <820622658@qq.com>

@mkanat mkanat left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I hit this bug through a bazel build of a Python project on Windows. A change very similar to this one fixes it for me. A few things I noticed:

  1. is_unc is also true for paths that already start with \\?\ or \\.\, which become \\?\UNC\?\.... So when an extension at such a path fails to load for an ordinary reason, such as the wrong architecture, the error becomes "The network path was not found" instead of the real one. For example, you can see bazel-contrib/rules_python#4071 already passes \\?\ paths, so its users would see this.
  2. Minor: Retrying only on ERROR_FILENAME_EXCED_RANGE (206) would leave any other error as it is today.
  3. Minor: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation says \\?\ paths are "passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory." GetFullPathNameW before adding the prefix would probably be safer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'ImportError: DLL load failed while importing xxxxxxx: The filename or extension is too long' with LongPathsEnabled

2 participants