-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition creating symlinks on Windows results in a junction to empty directory being created instead of a symlink to a file #19018
Comments
Possibly related: #2474 |
Another related issue: #12018 |
@carpenterjc Do you happen to have a repro you can share (even if it's not 100% deterministic and needs to be run a few times to hit the bug)? Please also include the flags you're invoking Bazel with. |
@tjgq I have a reproduction for causing windows to produce junctions instead of header file symlinks.
|
If you add in some extra dependencies and a manual target you can reporduce the compiler trying to open one of these junctions.
|
I'm going to close this as a duplicate of #21747 since the repro strongly suggests it's the same issue (i.e., you need a disk or remote cache and build without the bytes to reproduce it; if you can repro outside of these conditions, please reopen). |
Description of the bug:
While using a
cc_import
to add a dependency to acc_binary
that is produced by a custom starlark rule elsewhere in the repository.This executable is then use by and run by a
cc_test
.What we find is rarely bazel will create "symlink" the file before it is written by the custom rule. When this happens bazel will create a directory junction instead of a symlink to the file.
Sometimes what is supposed to be a symlink (or copy, if symlinks are disabled) shows up as a directory junction instead (this breaks -- you cannot interact with a directory junction which points at a file)
When you're in this state, bazel build doesn't fix the problem. Only a bazel clean or manually removing the junction fixes it.
It appears to be a race condition, because it doesn't happen consistently.
Code inspection of the bazel symlink implementation for Windows shows that it creates a directory junction either if the target exists and is a directory, or if the target doesn't exist -- even if symlinks are disabled on Windows.
This implies the bug: if the core.symlink action is scheduled ahead of the action which generates the link target, it will always produce the wrong result on Windows.
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
This happens rarely and we believe its a race condition.
Which operating system are you running Bazel on?
Windows 11
What is the output of
bazel info release
?release 6.2.0
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
No response
Have you found anything relevant by searching the web?
https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/windows/WindowsFileSystem.java#L80-L106
that says:
If the target doesn't exist, or if it is a directory, create a junction. We don't check the symlink flag for this case.
Else (the target exists and is a file)
If the symlink flag is enabled, create a symlink
Otherwise copy it (non-atomically, by the way)
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: