Skip to content

[9.2.0] Fix launching executables whose path can't be shortened on Windows (https://github.com/bazelbuild/bazel/pull/29921) - #29984

Merged
iancha1992 merged 1 commit into
bazelbuild:release-9.2.0from
bazel-io:cp29921-9.2.0-180506
Jun 25, 2026
Merged

[9.2.0] Fix launching executables whose path can't be shortened on Windows (https://github.com/bazelbuild/bazel/pull/29921)#29984
iancha1992 merged 1 commit into
bazelbuild:release-9.2.0from
bazel-io:cp29921-9.2.0-180506

Conversation

@bazel-io

Copy link
Copy Markdown
Member

Description

AsExecutablePathForCreateProcess shortens an executable's path with GetShortPathNameW so it fits CreateProcessW's MAX_PATH-bound command line, and currently fails outright when shortening can't bring it under MAX_PATH.
This change adds a fallback: it launches the executable through CreateProcessW's lpApplicationName, which is not subject to the MAX_PATH limit, in extended-length (\\?\) form.
Supplying lpApplicationName also lifts the MAX_PATH limit from the executable part of lpCommandLine, so the original path is kept there as argv[0].

Shortening is still attempted first, so the change is a pure superset of the current behavior: paths that shorten today are launched unchanged, and only the currently-failing ones take the fallback.
The fallback is limited to absolute, normalized paths to plain executables:

  • a batch file is not a valid lpApplicationName as it must be run through a command interpreter,
  • neither is a non-normalized path because its ./.. components would survive unresolved in the extended-length path.

The fix relies on \\?\ bypassing MAX_PATH at the path-parsing layer, independently of the LongPathsEnabled registry value and the longPathAware manifest.

Motivation

Fixes #19710.

Avoid errors like:

==================== Test output for //some/configuration/issues/invalidconfig:invalidconfig_test:
ERROR(tools/test/windows/tw.cc:1307) ERROR: src/main/native/windows/process.cc(82): WaitableProcess::Create(C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe): ERROR: src/main/native/windows/util.cc(292): AsExecutablePathForCreateProcess(C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe): ERROR: src/main/native/windows/util.cc(262): GetShortPathNameW(\\?\C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe): cannot shorten the path enough
ERROR(tools/test/windows/tw.cc:1517) Failed to start test process (arg: C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe)
================================================================================

Shortening fails in two situations, both handled here:

Prior art: Rust's std::process::Command passes a verbatim \\?\ path as lpApplicationName for a >MAX_PATH executable and special-cases batch files the same way:

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: Fixed Bazel being unable to run a Windows executable whose path is too long to shorten under MAX_PATH, e.g. when 8dot3 short names are disabled (microsoft/Windows-Containers#507).

Closes #29921.

PiperOrigin-RevId: 937426905
Change-Id: Ia48d41e000622fc122d1b258ad15daa5018be75e

Commit 4a80d43

…azelbuild#29921)

### Description
`AsExecutablePathForCreateProcess` shortens an executable's path with `GetShortPathNameW` so it fits `CreateProcessW`'s `MAX_PATH`-bound command line, and currently fails outright when shortening can't bring it under `MAX_PATH`.
This change adds a fallback: it launches the executable through `CreateProcessW`'s _lpApplicationName_, which is not subject to the `MAX_PATH` limit, in extended-length (`\\?\`) form.
Supplying _lpApplicationName_ also lifts the `MAX_PATH` limit from the executable part of _lpCommandLine_, so the original path is kept there as `argv[0]`.

Shortening is still attempted first, so the change is a pure superset of the current behavior: paths that shorten today are launched unchanged, and only the currently-failing ones take the fallback.
The fallback is limited to absolute, normalized paths to plain executables:
- a batch file is not a valid _lpApplicationName_ as it must be run through a command interpreter,
- neither is a non-normalized path because its `.`/`..` components would survive unresolved in the extended-length path.

The fix relies on `\\?\` bypassing `MAX_PATH` at the path-parsing layer, **independently** of the _LongPathsEnabled_ registry value and the _longPathAware_ manifest.

### Motivation
Fixes bazelbuild#19710.

Avoid errors like:
```
==================== Test output for //some/configuration/issues/invalidconfig:invalidconfig_test:
ERROR(tools/test/windows/tw.cc:1307) ERROR: src/main/native/windows/process.cc(82): WaitableProcess::Create(C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe): ERROR: src/main/native/windows/util.cc(292): AsExecutablePathForCreateProcess(C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe): ERROR: src/main/native/windows/util.cc(262): GetShortPathNameW(\\?\C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe): cannot shorten the path enough
ERROR(tools/test/windows/tw.cc:1517) Failed to start test process (arg: C:\user\execroot\_main\bazel-out\x64_windows-fastbuild-ST-000000000001\bin\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe.runfiles\_main\some\configuration\issues\invalidconfig\invalidconfig_test_\invalidconfig_test.exe)
================================================================================
```

Shortening fails in two situations, both handled here:
- 8dot3 short-name creation is disabled on the volume (common in containers, microsoft/Windows-Containers#507), so `GetShortPathNameW` is a no-op and a long runfiles executable path stays over `MAX_PATH`,
- the path is nested so deeply that even fully 8dot3-shortened it still overflows `MAX_PATH`.

Prior art: Rust's `std::process::Command` passes a verbatim `\\?\` path as _lpApplicationName_ for a >`MAX_PATH` executable and special-cases batch files the same way:
- rust-lang/rust#87704,
- rust-lang/rust#92519.

### Build API Changes
No

### Checklist
- [x] I have added tests for the new use cases (if any).
- [ ] I have updated the documentation (if applicable).

### Release Notes
RELNOTES: Fixed Bazel being unable to run a Windows executable whose path is too long to shorten under `MAX_PATH`, e.g. when 8dot3 short names are disabled (microsoft/Windows-Containers#507).

Closes bazelbuild#29921.

PiperOrigin-RevId: 937426905
Change-Id: Ia48d41e000622fc122d1b258ad15daa5018be75e
@bazel-io
bazel-io requested a review from a team as a code owner June 24, 2026 18:06
@bazel-io bazel-io added area-Windows Windows-specific issues and feature requests team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website awaiting-review PR is awaiting review from an assigned reviewer labels Jun 24, 2026
@bazel-io
bazel-io requested a review from fmeum June 24, 2026 18:06
@bazel-io bazel-io added the awaiting-review PR is awaiting review from an assigned reviewer label Jun 24, 2026
@iancha1992
iancha1992 enabled auto-merge June 24, 2026 18:33
@iancha1992
iancha1992 requested review from Wyverald and removed request for fmeum June 24, 2026 18:34
@iancha1992
iancha1992 added this pull request to the merge queue Jun 25, 2026
Merged via the queue into bazelbuild:release-9.2.0 with commit 313773c Jun 25, 2026
46 checks passed
@github-actions github-actions Bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Jun 25, 2026
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/datadog-agent that referenced this pull request Jul 14, 2026
### What does this PR do?
Bump the pinned Bazel version from 9.1.1 to 9.2.0 and refresh `MODULE.bazel.lock` accordingly.

### Motivation
Bazel 9.2.0 ships fixes this repo has been working around over the past month.

#### Windows issues
Our contributions:
- bazelbuild/bazel#29984, which should remove the need for temporary countermeasures we had to come up with:
  - DataDog/datadog-agent-buildimages#1212 (alas ineffective),
  - DataDog/datadog-agent-buildimages#1215 (effective),
  - #52500,
- bazelbuild/bazel#30182, which should remove the need for:
  - #52061,
  - #53591.

#### Caching issues
- bazelbuild/bazel#29791,
- bazelbuild/bazel#29868,
- bazelbuild/bazel#29885,
- bazelbuild/bazel#30193, a caveat mentioned in:
  - #53356.

#### Others
Also worth noting, though not tied to a specific incident here:
- bazelbuild/bazel#29807,
- bazelbuild/bazel#29898,
- bazelbuild/bazel#30194.

### Describe how you validated your changes
`bazel version` reports 9.2.0 after `bazelisk` re-bootstraps.
`bazel build //pkg/config/schema/...` completes successfully.
`bazel shutdown` followed by `bazel mod deps --lockfile_mode=refresh` leaves `MODULE.bazel.lock` unchanged.

### Additional Notes
None of the .bazelrc UAC/8dot3 workarounds (DataDog/datadog-agent-buildimages#1215, #52500, #52061, #53591) are removed here.
Each needs its own re-verification on Windows before being reverted as follow-ups.

Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/datadog-agent that referenced this pull request Aug 21, 2026
…xes (#53619) (#55228)

Bump the pinned Bazel version from 9.1.1 to 9.2.0 and refresh `MODULE.bazel.lock` accordingly.

Bazel 9.2.0 ships fixes this repo has been working around over the past month.

Our contributions:
- bazelbuild/bazel#29984, which should remove the need for temporary countermeasures we had to come up with:
  - DataDog/datadog-agent-buildimages#1212 (alas ineffective),
  - DataDog/datadog-agent-buildimages#1215 (effective),
  - #52500,
- bazelbuild/bazel#30182, which should remove the need for:
  - #52061,
  - #53591.

- bazelbuild/bazel#29791,
- bazelbuild/bazel#29868,
- bazelbuild/bazel#29885,
- bazelbuild/bazel#30193, a caveat mentioned in:
  - #53356.

Also worth noting, though not tied to a specific incident here:
- bazelbuild/bazel#29807,
- bazelbuild/bazel#29898,
- bazelbuild/bazel#30194.

`bazel version` reports 9.2.0 after `bazelisk` re-bootstraps. `bazel build //pkg/config/schema/...` completes successfully. `bazel shutdown` followed by `bazel mod deps --lockfile_mode=refresh` leaves `MODULE.bazel.lock` unchanged.

None of the .bazelrc UAC/8dot3 workarounds (DataDog/datadog-agent-buildimages#1215, #52500, #52061, #53591) are removed here. Each needs its own re-verification on Windows before being reverted as follow-ups.


(cherry picked from commit 695123c)

<!--Please give us some feedback on your experience writing this PR ! https://app.datadoghq.com/forms/43db4c02-6837-400c-8083-692e141b1b88 !-->

### What does this PR do?

### Motivation

### Describe how you validated your changes

### Additional Notes


Co-authored-by: rdesgroppes <rdesgroppes@gmail.com>
Co-authored-by: ali.benabdallah <ali.benabdallah@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Windows Windows-specific issues and feature requests team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants