Skip to content
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

Windows: cannot delete file from test's temp directory #7173

Closed
laszlocsomor opened this issue Jan 18, 2019 · 0 comments
Closed

Windows: cannot delete file from test's temp directory #7173

laszlocsomor opened this issue Jan 18, 2019 · 0 comments
Assignees
Labels
area-Windows Windows-specific issues and feature requests P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug

Comments

@laszlocsomor
Copy link
Contributor

Description of the problem / feature request:

While repeatedly running tests, I somehow ended up with a stale file in the test's temp directory that Bazel was unable to delete.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  1. Build Bazel at 356ad22
  2. Create the following simple workspace:
  • WORKSPACE file: empty
  • BUILD file: sh_test(name="x", srcs=["test.sh"])
  • test.sh file: #!/bin/true
  1. Use the custom Bazel to run the test: devbazel.exe test :x
  2. Run devbazel.exe info execution_root, copy-paste the result to a temporary text file somewhere. For me this is C:/_bazel/iwcf5f5r/execroot/__main__.
  3. Under this directory there's _tmp/, under which there's only one directory with a name that looks like a hash code. Mine is 5eb2acb906008def159de940fca5b1a2/.
  4. Under that directory, we'll create the workspace/NUL file. I don't know how I originally ended up with this file, but this is what triggers the bug. Create it like so: mkdir -p C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace && touch C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace/NUL
  5. Run the test again with -t-: devbazel.exe test -t- :x
  6. Witness this crash:
[0 / 5] [-----] BazelWorkspaceStatusAction stable-status.txt
ERROR: Caught I/O exception: Cannot delete path 'C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace/NUL': ERROR: src/main/native/windows/file-jni.cc(104): nativeDeletePath(C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace/NUL): ERROR: src/main/native/windows/file.cc(451): SetFileAttributesW(C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace/NUL): Incorrect function.

        com.google.devtools.build.lib.windows.jni.WindowsFileOperations.deletePath(WindowsFileOperations.java:177)
        com.google.devtools.build.lib.windows.WindowsFileSystem.delete(WindowsFileSystem.java:58)
        com.google.devtools.build.lib.vfs.Path.delete(Path.java:686)
        com.google.devtools.build.lib.vfs.FileSystemUtils.deleteTree(FileSystemUtils.java:529)
        com.google.devtools.build.lib.vfs.FileSystemUtils.deleteTreesBelow(FileSystemUtils.java:545)
        com.google.devtools.build.lib.vfs.FileSystemUtils.deleteTree(FileSystemUtils.java:528)
        com.google.devtools.build.lib.vfs.FileSystemUtils.deleteTreesBelow(FileSystemUtils.java:545)
        com.google.devtools.build.lib.vfs.FileSystemUtils.deleteTree(FileSystemUtils.java:528)
        com.google.devtools.build.lib.exec.TestStrategy.recreateDirectory(TestStrategy.java:81)
        com.google.devtools.build.lib.exec.TestStrategy.prepareFileSystem(TestStrategy.java:75)
        com.google.devtools.build.lib.exec.StandaloneTestStrategy.executeTestAttempt(StandaloneTestStrategy.java:317)
        com.google.devtools.build.lib.exec.StandaloneTestStrategy.exec(StandaloneTestStrategy.java:143)
        com.google.devtools.build.lib.rules.test.ExclusiveTestStrategy.exec(ExclusiveTestStrategy.java:47)
        com.google.devtools.build.lib.analysis.test.TestRunnerAction.execute(TestRunnerAction.java:743)
        com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.executeAction(SkyframeActionExecutor.java:901)
        com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.call(SkyframeActionExecutor.java:866)
        com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.call(SkyframeActionExecutor.java:799)
        java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.executeAction(SkyframeActionExecutor.java:550)
        com.google.devtools.build.lib.skyframe.ActionExecutionFunction.checkCacheAndExecuteIfNeeded(ActionExecutionFunction.java:701)
        com.google.devtools.build.lib.skyframe.ActionExecutionFunction.compute(ActionExecutionFunction.java:243)
        com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:437)
        com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:368)
        java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        java.base/java.lang.Thread.run(Unknown Source)
ERROR: C:/src/tmp3/BUILD:1:1:  failed: unexpected I/O exception: Cannot delete path 'C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace/NUL': ERROR: src/main/native/windows/file-jni.cc(104): nativeDeletePath(C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace/NUL): ERROR: src/main/native/windows/file.cc(451): SetFileAttributesW(C:/_bazel/iwcf5f5r/execroot/__main__/_tmp/5eb2acb906008def159de940fca5b1a2/workspace/NUL): Incorrect function.

I found out that the culprit is that src/main/native/windows/file.cc:DeletePath receives a path with forward slashes and does not convert it to Windows-style-with-UNC-prefix before passing it to Windows API functions.

What operating system are you running Bazel on?

Windows 10

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

see repro above

@laszlocsomor laszlocsomor self-assigned this Jan 18, 2019
@laszlocsomor laszlocsomor added type: bug P1 I'll work on this now. (Assignee required) area-Windows Windows-specific issues and feature requests labels Jan 18, 2019
laszlocsomor added a commit to laszlocsomor/bazel that referenced this issue Jan 18, 2019
DeletePath now verifies that the input path is
Windows-style (i.e. uses backslashes) and
absolute, and adds the `\\?\` prefix to the path.

Doing so ensures it can delete any file (including
degenerately-named ones like `c:\foo\nul`).

Fixes bazelbuild#7173
laszlocsomor added a commit to laszlocsomor/bazel that referenced this issue Jan 18, 2019
DeletePath now verifies that the input path is
Windows-style (i.e. uses backslashes) and
absolute, and adds the `\\?\` prefix to the path.

Doing so ensures it can delete any file (including
degenerately-named ones like `c:\foo\nul`).

Fixes bazelbuild#7173
weixiao-huang pushed a commit to weixiao-huang/bazel that referenced this issue Jan 31, 2019
DeletePath now verifies that the input path is
Windows-style (i.e. uses backslashes) and
absolute, and adds the `\\?\` prefix to the path.

Doing so ensures it can delete any file (including
degenerately-named ones like `c:\foo\nul`).

Fixes bazelbuild#7173

Closes bazelbuild#7176.

PiperOrigin-RevId: 229913623
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
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 P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants