Repository navigation
fix: Mitigate the -L dependency= consolidation races on Windows - #48
Merged
dzbarsky merged 1 commit intoSep 1, 2026
Conversation
ArchangelX360
commented
Sep 1, 2026
Member
``` On Windows, consolidate_dependency_search_paths (util/process_wrapper/main.rs:156) collapses every -Ldependency=<dir> rustc flag into one unified directory, to avoid Windows command-line size overruns (commit 3f613e4). It does so by read_dir-ing each search path and hardlinking (falling back to copying) every regular file it finds into that unified dir. However, builds failed with: Error: ProcessWrapperError("unable to copy .../ijent_util-subscriber_contract-test.exe.tmp8ceb5a4 into unified dependency dir ...: Access is denied. (os error 5)") .exe.tmpXXXXXXX file is an LLVM's atomic-output temp file. Every LLVM tool that writes output this way does it: lld-link / rust-lld (the PE image and the PDB), llvm-lib (import libs), llvm-objcopy. So this file is rust-lld writing the sibling target ijent_util-subscriber_contract-test.exe. It only occurs with toolchain.linker_preference == "rust" (rustc.bzl:445-448); MSVC's link.exe writes in place. Lifecycle of that temp file ┌────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Phase │ What happens │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Created │ At the start of the sibling's link step. TempFile::create passes OF_Delete, then immediately calls │ │ │ setDeleteDisposition(H, true) → DELETE_PENDING from birth. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Alive │ For the entire duration of that link, while lld mmaps and writes the image into it. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ FileOutputBuffer::commit() → TempFile::keep(FinalPath): setDeleteDisposition(H, false), then rename_handle(H, │ │ (success) │ "…-test.exe"). The temp name vanishes by rename. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ TempFile::discard() — the already-set delete disposition does it on close; RemoveFileOnSignal covers crashes. │ │ (failure) │ │ └────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ Why os error 5 and not os error 2 Because of DELETE_PENDING. On Windows a delete-pending file: - still appears in directory enumeration — fs::read_dir yields it and entry.file_type() succeeds (metadata comes from the dirent); - but every CreateFile on it fails with STATUS_DELETE_PENDING → ERROR_ACCESS_DENIED (5). So fs::hard_link (CreateHardLinkW) fails with 5, the fs::copy (CopyFileExW) fallback fails with 5, and the wrapper escalates to a fatal ProcessWrapperError. LLVM's own createUniqueEntity retries on errc::permission_denied for exactly this reason. This is not a narrow race. The window is the whole link of the sibling target, and the failure is deterministic once read_dir observes the temp file. Why the temp file is in a -L dependency= directory at all rust/private/rustc.bzl:2994-2998 derives the search paths from the dirnames of dep_info.transitive_crate_outputs (_get_dirname, rustc.bzl:3433). A dirname is an entire Bazel package bin dir (bazel-out/<cfg>/bin/fleet/native/ijent/ijent_util/) containing every output of that package — sibling .exes, .pdbs, .os, .rustc-outputs, tree artifacts, in-flight linker temps — not a curated set of crate artifacts. Bazel has no sandboxing on Windows, so those scanned directories are the live bazel-out tree with every concurrent action's activity visible. ```
Member
Author
|
The proper fix would probably be to stop scanning that |
dzbarsky
approved these changes
Sep 1, 2026
genevieve-me
pushed a commit
to genevieve-me/rules_rust
that referenced
this pull request
Sep 8, 2026
…eticbuild#48) ``` On Windows, consolidate_dependency_search_paths (util/process_wrapper/main.rs:156) collapses every -Ldependency=<dir> rustc flag into one unified directory, to avoid Windows command-line size overruns (commit 3f613e4). It does so by read_dir-ing each search path and hardlinking (falling back to copying) every regular file it finds into that unified dir. However, builds failed with: Error: ProcessWrapperError("unable to copy .../ijent_util-subscriber_contract-test.exe.tmp8ceb5a4 into unified dependency dir ...: Access is denied. (os error 5)") .exe.tmpXXXXXXX file is an LLVM's atomic-output temp file. Every LLVM tool that writes output this way does it: lld-link / rust-lld (the PE image and the PDB), llvm-lib (import libs), llvm-objcopy. So this file is rust-lld writing the sibling target ijent_util-subscriber_contract-test.exe. It only occurs with toolchain.linker_preference == "rust" (rustc.bzl:445-448); MSVC's link.exe writes in place. Lifecycle of that temp file ┌────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Phase │ What happens │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Created │ At the start of the sibling's link step. TempFile::create passes OF_Delete, then immediately calls │ │ │ setDeleteDisposition(H, true) → DELETE_PENDING from birth. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Alive │ For the entire duration of that link, while lld mmaps and writes the image into it. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ FileOutputBuffer::commit() → TempFile::keep(FinalPath): setDeleteDisposition(H, false), then rename_handle(H, │ │ (success) │ "…-test.exe"). The temp name vanishes by rename. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ TempFile::discard() — the already-set delete disposition does it on close; RemoveFileOnSignal covers crashes. │ │ (failure) │ │ └────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ Why os error 5 and not os error 2 Because of DELETE_PENDING. On Windows a delete-pending file: - still appears in directory enumeration — fs::read_dir yields it and entry.file_type() succeeds (metadata comes from the dirent); - but every CreateFile on it fails with STATUS_DELETE_PENDING → ERROR_ACCESS_DENIED (5). So fs::hard_link (CreateHardLinkW) fails with 5, the fs::copy (CopyFileExW) fallback fails with 5, and the wrapper escalates to a fatal ProcessWrapperError. LLVM's own createUniqueEntity retries on errc::permission_denied for exactly this reason. This is not a narrow race. The window is the whole link of the sibling target, and the failure is deterministic once read_dir observes the temp file. Why the temp file is in a -L dependency= directory at all rust/private/rustc.bzl:2994-2998 derives the search paths from the dirnames of dep_info.transitive_crate_outputs (_get_dirname, rustc.bzl:3433). A dirname is an entire Bazel package bin dir (bazel-out/<cfg>/bin/fleet/native/ijent/ijent_util/) containing every output of that package — sibling .exes, .pdbs, .os, .rustc-outputs, tree artifacts, in-flight linker temps — not a curated set of crate artifacts. Bazel has no sandboxing on Windows, so those scanned directories are the live bazel-out tree with every concurrent action's activity visible. ```
dzbarsky
pushed a commit
that referenced
this pull request
Sep 23, 2026
``` On Windows, consolidate_dependency_search_paths (util/process_wrapper/main.rs:156) collapses every -Ldependency=<dir> rustc flag into one unified directory, to avoid Windows command-line size overruns (commit 3f613e4). It does so by read_dir-ing each search path and hardlinking (falling back to copying) every regular file it finds into that unified dir. However, builds failed with: Error: ProcessWrapperError("unable to copy .../ijent_util-subscriber_contract-test.exe.tmp8ceb5a4 into unified dependency dir ...: Access is denied. (os error 5)") .exe.tmpXXXXXXX file is an LLVM's atomic-output temp file. Every LLVM tool that writes output this way does it: lld-link / rust-lld (the PE image and the PDB), llvm-lib (import libs), llvm-objcopy. So this file is rust-lld writing the sibling target ijent_util-subscriber_contract-test.exe. It only occurs with toolchain.linker_preference == "rust" (rustc.bzl:445-448); MSVC's link.exe writes in place. Lifecycle of that temp file ┌────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Phase │ What happens │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Created │ At the start of the sibling's link step. TempFile::create passes OF_Delete, then immediately calls │ │ │ setDeleteDisposition(H, true) → DELETE_PENDING from birth. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Alive │ For the entire duration of that link, while lld mmaps and writes the image into it. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ FileOutputBuffer::commit() → TempFile::keep(FinalPath): setDeleteDisposition(H, false), then rename_handle(H, │ │ (success) │ "…-test.exe"). The temp name vanishes by rename. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ TempFile::discard() — the already-set delete disposition does it on close; RemoveFileOnSignal covers crashes. │ │ (failure) │ │ └────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ Why os error 5 and not os error 2 Because of DELETE_PENDING. On Windows a delete-pending file: - still appears in directory enumeration — fs::read_dir yields it and entry.file_type() succeeds (metadata comes from the dirent); - but every CreateFile on it fails with STATUS_DELETE_PENDING → ERROR_ACCESS_DENIED (5). So fs::hard_link (CreateHardLinkW) fails with 5, the fs::copy (CopyFileExW) fallback fails with 5, and the wrapper escalates to a fatal ProcessWrapperError. LLVM's own createUniqueEntity retries on errc::permission_denied for exactly this reason. This is not a narrow race. The window is the whole link of the sibling target, and the failure is deterministic once read_dir observes the temp file. Why the temp file is in a -L dependency= directory at all rust/private/rustc.bzl:2994-2998 derives the search paths from the dirnames of dep_info.transitive_crate_outputs (_get_dirname, rustc.bzl:3433). A dirname is an entire Bazel package bin dir (bazel-out/<cfg>/bin/fleet/native/ijent/ijent_util/) containing every output of that package — sibling .exes, .pdbs, .os, .rustc-outputs, tree artifacts, in-flight linker temps — not a curated set of crate artifacts. Bazel has no sandboxing on Windows, so those scanned directories are the live bazel-out tree with every concurrent action's activity visible. ```
ArchangelX360
added a commit
to ArchangelX360/rules_rust
that referenced
this pull request
Oct 5, 2026
… `cc_common.link` Keep `.a` files out of the unified dependency directory of the Windows process wrapper. On Windows, `process_wrapper` merges every `-Ldependency=` directory into one, to keep the command line short. It scans each directory with `read_dir`, so it also sees files that are no input of the action. `rules_rust` puts a `lib<name>.a` symlink next to each rlib, for `cc_common.link`. With `experimental_use_cc_common_link`, Bazel builds those symlinks while sibling `Rustc` actions scan the directory, and the copy fails with "Access is denied". `-L dependency=` only searches for crates, and no crate is a `.a` file, so skip the extension. Relates to hermeticbuild#48
dzbarsky
pushed a commit
that referenced
this pull request
Oct 5, 2026
… `cc_common.link` (#82) Keep `.a` files out of the unified dependency directory of the Windows process wrapper. On Windows, `process_wrapper` merges every `-Ldependency=` directory into one, to keep the command line short. It scans each directory with `read_dir`, so it also sees files that are no input of the action. `rules_rust` puts a `lib<name>.a` symlink next to each rlib, for `cc_common.link`. With `experimental_use_cc_common_link`, Bazel builds those symlinks while sibling `Rustc` actions scan the directory, and the copy fails with "Access is denied". `-L dependency=` only searches for crates, and no crate is a `.a` file, so skip the extension. Relates to #48
walter-zeromatter
pushed a commit
to ZeromatterOSS/rules_rust
that referenced
this pull request
Nov 6, 2026
… `cc_common.link` (bazelbuild#82) Keep `.a` files out of the unified dependency directory of the Windows process wrapper. On Windows, `process_wrapper` merges every `-Ldependency=` directory into one, to keep the command line short. It scans each directory with `read_dir`, so it also sees files that are no input of the action. `rules_rust` puts a `lib<name>.a` symlink next to each rlib, for `cc_common.link`. With `experimental_use_cc_common_link`, Bazel builds those symlinks while sibling `Rustc` actions scan the directory, and the copy fails with "Access is denied". `-L dependency=` only searches for crates, and no crate is a `.a` file, so skip the extension. Relates to hermeticbuild#48
dzbarsky
pushed a commit
that referenced
this pull request
Nov 30, 2026
``` On Windows, consolidate_dependency_search_paths (util/process_wrapper/main.rs:156) collapses every -Ldependency=<dir> rustc flag into one unified directory, to avoid Windows command-line size overruns (commit 3f613e4). It does so by read_dir-ing each search path and hardlinking (falling back to copying) every regular file it finds into that unified dir. However, builds failed with: Error: ProcessWrapperError("unable to copy .../ijent_util-subscriber_contract-test.exe.tmp8ceb5a4 into unified dependency dir ...: Access is denied. (os error 5)") .exe.tmpXXXXXXX file is an LLVM's atomic-output temp file. Every LLVM tool that writes output this way does it: lld-link / rust-lld (the PE image and the PDB), llvm-lib (import libs), llvm-objcopy. So this file is rust-lld writing the sibling target ijent_util-subscriber_contract-test.exe. It only occurs with toolchain.linker_preference == "rust" (rustc.bzl:445-448); MSVC's link.exe writes in place. Lifecycle of that temp file ┌────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Phase │ What happens │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Created │ At the start of the sibling's link step. TempFile::create passes OF_Delete, then immediately calls │ │ │ setDeleteDisposition(H, true) → DELETE_PENDING from birth. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Alive │ For the entire duration of that link, while lld mmaps and writes the image into it. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ FileOutputBuffer::commit() → TempFile::keep(FinalPath): setDeleteDisposition(H, false), then rename_handle(H, │ │ (success) │ "…-test.exe"). The temp name vanishes by rename. │ ├────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Deleted │ TempFile::discard() — the already-set delete disposition does it on close; RemoveFileOnSignal covers crashes. │ │ (failure) │ │ └────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ Why os error 5 and not os error 2 Because of DELETE_PENDING. On Windows a delete-pending file: - still appears in directory enumeration — fs::read_dir yields it and entry.file_type() succeeds (metadata comes from the dirent); - but every CreateFile on it fails with STATUS_DELETE_PENDING → ERROR_ACCESS_DENIED (5). So fs::hard_link (CreateHardLinkW) fails with 5, the fs::copy (CopyFileExW) fallback fails with 5, and the wrapper escalates to a fatal ProcessWrapperError. LLVM's own createUniqueEntity retries on errc::permission_denied for exactly this reason. This is not a narrow race. The window is the whole link of the sibling target, and the failure is deterministic once read_dir observes the temp file. Why the temp file is in a -L dependency= directory at all rust/private/rustc.bzl:2994-2998 derives the search paths from the dirnames of dep_info.transitive_crate_outputs (_get_dirname, rustc.bzl:3433). A dirname is an entire Bazel package bin dir (bazel-out/<cfg>/bin/fleet/native/ijent/ijent_util/) containing every output of that package — sibling .exes, .pdbs, .os, .rustc-outputs, tree artifacts, in-flight linker temps — not a curated set of crate artifacts. Bazel has no sandboxing on Windows, so those scanned directories are the live bazel-out tree with every concurrent action's activity visible. ```
dzbarsky
pushed a commit
that referenced
this pull request
Nov 30, 2026
… `cc_common.link` (#82) Keep `.a` files out of the unified dependency directory of the Windows process wrapper. On Windows, `process_wrapper` merges every `-Ldependency=` directory into one, to keep the command line short. It scans each directory with `read_dir`, so it also sees files that are no input of the action. `rules_rust` puts a `lib<name>.a` symlink next to each rlib, for `cc_common.link`. With `experimental_use_cc_common_link`, Bazel builds those symlinks while sibling `Rustc` actions scan the directory, and the copy fails with "Access is denied". `-L dependency=` only searches for crates, and no crate is a `.a` file, so skip the extension. Relates to #48
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.