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: rebuild and clean sometimes fail with DirectoryNotEmptyException #5907

Closed
meteorcloudy opened this issue Aug 16, 2018 · 22 comments
Closed
Assignees
Labels
area-Windows Windows-specific issues and feature requests P2 We'll consider working on this in future. (Assignee optional) platform: windows team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug

Comments

@meteorcloudy
Copy link
Member

When I use Bazel 0.15.2 to rebuild Bazel I got this error sometimes:

ERROR: C:/tools/msys64/home/pcloudy/workspace/bazel/src/main/java/com/google/devtools/build/skyframe/BUILD:25:1: Building src/main/java/com/google/devtools/build/skyframe/libskyframe.jar (72 source files) and running annotation processors (AutoCodecProcessor, OptionProcessor) failed (Exit 1): java.exe failed: error executing command
  cd C:/users/pcloudy/_bazel_pcloudy/3uxo2r6v/execroot/io_bazel
  SET LC_CTYPE=en_US.UTF-8
  external/embedded_jdk/bin/java.exe -Xbootclasspath/p:external/bazel_tools/third_party/java/jdk/langtools/javac-9+181-r4173-1.jar -jar external/bazel_tools/tools/jdk/JavaBuilder_deploy.jar @bazel-out/x64_windows-fastbuild/bin/src/main/java/com/google/devtools/build/skyframe/libskyframe.jar-2.params
java.io.IOException: Cannot clean 'bazel-out\x64_windows-fastbuild\bin\src\main\java\com\google\devtools\build\skyframe\_javac\skyframe\libskyframe_classes'
        at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.cleanupDirectory(SimpleJavaLibraryBuilder.java:91)
        at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.prepareSourceCompilation(SimpleJavaLibraryBuilder.java:53)
        at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.compileJavaLibrary(SimpleJavaLibraryBuilder.java:113)
        at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.run(SimpleJavaLibraryBuilder.java:132)
        at com.google.devtools.build.buildjar.BazelJavaBuilder.processRequest(BazelJavaBuilder.java:105)
        at com.google.devtools.build.buildjar.BazelJavaBuilder.runPersistentWorker(BazelJavaBuilder.java:67)
        at com.google.devtools.build.buildjar.BazelJavaBuilder.main(BazelJavaBuilder.java:45)
Caused by: java.nio.file.DirectoryNotEmptyException: bazel-out\x64_windows-fastbuild\bin\src\main\java\com\google\devtools\build\skyframe\_javac\skyframe\libskyframe_classes\com\google\devtools\build
        at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:266)
        at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
        at java.nio.file.Files.delete(Files.java:1126)
        at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder$1.postVisitDirectory(SimpleJavaLibraryBuilder.java:85)
        at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder$1.postVisitDirectory(SimpleJavaLibraryBuilder.java:73)
        at java.nio.file.Files.walkFileTree(Files.java:2688)
        at java.nio.file.Files.walkFileTree(Files.java:2742)
        at com.google.devtools.build.buildjar.SimpleJavaLibraryBuilder.cleanupDirectory(SimpleJavaLibraryBuilder.java:71)
        ... 6 more
Target //src:bazel failed to build
INFO: Elapsed time: 36.284s, Critical Path: 14.20s
INFO: 44 processes: 23 local, 21 worker.
FAILED: Build did NOT complete successfully

pcloudy@pcloudy0-w MSYS ~/workspace/bazel
$ bazel clean
Starting local Bazel server and connecting to it...
INFO: Starting clean.
ERROR: C:/users/pcloudy/_bazel_pcloudy/3uxo2r6v/execroot/io_bazel/bazel-out/x64_windows-fastbuild/bin/src/main/java/com/google/devtools/build/lib/remote/blobstore/_javac/blobstore/libblobstore_classes/com/google (Directory not empty)

pcloudy@pcloudy0-w MSYS ~/workspace/bazel
$ ls /c/users/pcloudy/_bazel_pcloudy/3uxo2r6v/execroot/io_bazel/bazel-out/x64_windows-fastbuild/bin/src/main/java/com/google/devtools/build/lib/remote/blobstore/_javac/blobstore/libblobstore_classes/com/google

pcloudy@pcloudy0-w MSYS ~/workspace/bazel
$ bazel clean
INFO: Starting clean.
ERROR: C:/users/pcloudy/_bazel_pcloudy/3uxo2r6v/execroot/io_bazel/bazel-out/x64_windows-fastbuild (Directory not empty)

pcloudy@pcloudy0-w MSYS ~/workspace/bazel
$ bazel clean
INFO: Starting clean.

FYI @laszlocsomor

@meteorcloudy meteorcloudy added type: bug P1 I'll work on this now. (Assignee required) platform: windows area-Windows Windows-specific issues and feature requests labels Aug 16, 2018
@laszlocsomor laszlocsomor self-assigned this Aug 16, 2018
@laszlocsomor
Copy link
Contributor

Does bazel clean eventually succeed?

@meteorcloudy
Copy link
Member Author

Yes, it took me three times although.

@laszlocsomor
Copy link
Contributor

Can you repro reliably?

@meteorcloudy
Copy link
Member Author

It happens constantly for me in the following situation:

# Clone bazel repo @ HEAD
$ bazel build //src:bazel
$ git reset 4c9149d --hard
$ bazel build //src:bazel

@meteorcloudy
Copy link
Member Author

But I'm using 0.15.2, I'll try if it still happens with 0.16.1

@laszlocsomor
Copy link
Contributor

I believe @meteorcloudy is working on this -- reassigning.

bazel-io pushed a commit that referenced this issue Aug 22, 2018
…an up directory

Related: #5907

RELNOTES: None
PiperOrigin-RevId: 209735282
@laszlocsomor
Copy link
Contributor

@meteorcloudy , have you seen this error with recent releases?

@meteorcloudy
Copy link
Member Author

meteorcloudy commented Nov 19, 2018

I haven't seen this after setting my output user root to C:/src/tmp, I guess it has something to do with the Windows Defender. I didn't receive any bug report from users, either. So I think it's fine to close issue.

@meteorcloudy
Copy link
Member Author

meteorcloudy commented Jan 10, 2019

Reopen since @laszlocsomor and I have both been seeing this issue for a while again, I'll look into it.

@meteorcloudy meteorcloudy reopened this Jan 10, 2019
meteorcloudy added a commit to meteorcloudy/bazel that referenced this issue Feb 19, 2019
`bazel clean` command sometimes fails on Windows with
"Directory not empty" error. But when checking the directory after the
failure, we don't see any file or directory under it.
After debugging, we cannot find any unclosed file handle, either.

However, when trying to delete the bazel output directory with `rm -rf" it
succeeds everytime. The reason is that Cygwin worked around a Windows
issue at this commit:
Alexpux/Cygwin@28fa2a7

The problem is, I quote:
""
Intensive testing shows that sometimes directories, for which
the delete disposition has already been set, and the deleting
handle is already closed, can linger in the parent dir for a
couple of ms for no apparent reason (Windows Defender or other
real-time scanners are suspect).
""

In this commit, we use a similar way to retry deleting the directory when
its "deleted" sub-dirs are still lingering under it.

Related bazelbuild#5907
@meteorcloudy
Copy link
Member Author

@laszlocsomor
Copy link
Contributor

Related stackoverflow question: https://stackoverflow.com/questions/31606978/odd-behaviour-when-deleting-files-with-files-delete

That was a great read, thanks!

bazel-io pushed a commit that referenced this issue Feb 20, 2019
`bazel clean` command sometimes fails on Windows with
"Directory not empty" error. But when checking the directory after the
failure, we don't see any file or directory under it.
After debugging, we cannot find any unclosed file handle, either.

However, when trying to delete the bazel output directory with `rm -rf" it
succeeds everytime. The reason is that Cygwin worked around a Windows
issue at this commit:
Alexpux/Cygwin@28fa2a7

The problem is, I quote:
""
Intensive testing shows that sometimes directories, for which
the delete disposition has already been set, and the deleting
handle is already closed, can linger in the parent dir for a
couple of ms for no apparent reason (Windows Defender or other
real-time scanners are suspect).
""

In this commit, we use a similar way to retry deleting the directory when
its "deleted" sub-dirs are still lingering under it.

Related #5907

Closes #7462.

PiperOrigin-RevId: 234777436
@laszlocsomor
Copy link
Contributor

@meteorcloudy : Can we close this bug?

@laszlocsomor
Copy link
Contributor

ping

@meteorcloudy
Copy link
Member Author

@laszlocsomor Sorry for the late response. Not yet, because in the JavaSimpleLibraryBuilder I sometimes still get DirectoryNotEmpty exception while rebuilding. It is not using our JNI code to delete file and directory, instead it uses MoreFiles.deleteRecursively from guava.

Did you ever have the same error?

@laszlocsomor
Copy link
Contributor

laszlocsomor commented Mar 4, 2019

Thanks for the update!

I don't remember clearly anymore if I've seen it or not.

@meteorcloudy
Copy link
Member Author

Basically I can reproduce after about 50 commits change in Bazel repo,
eg.

$ bazel build //src:bazel
$ git reset HEAD~50 --hard
$ bazel build //src:bazel

@laszlocsomor
Copy link
Contributor

@meteorcloudy : Any updates? Is P1 still adequate?

@meteorcloudy
Copy link
Member Author

I am not working on this recently. I'm not getting any report from users, so I guess P2 should be more appropriate. But I can still reproduce this bug on my local machine, so I'll keep it open.

@meteorcloudy meteorcloudy added P2 We'll consider working on this in future. (Assignee optional) and removed P1 I'll work on this now. (Assignee required) labels Apr 5, 2019
@laszlocsomor
Copy link
Contributor

Hey @meteorcloudy , I'd like to take a look at this. Can you still repro this locally? Could you help me repro?

@meteorcloudy
Copy link
Member Author

@laszlocsomor , thanks!
Yes, I can still repo this, basically following #5907 (comment)

@meteorcloudy
Copy link
Member Author

meteorcloudy commented Apr 29, 2019

Just reset to an old enough commit which will trigger a rebuild for most of Java code.

@meteorcloudy
Copy link
Member Author

This issue will be fixed from guava side, there's internal work going on, so I'm closing this one.

@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
…ean up directory

    Related: bazelbuild/bazel#5907

    RELNOTES: None
    PiperOrigin-RevId: 209735282
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 P2 We'll consider working on this in future. (Assignee optional) platform: windows team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug
Projects
None yet
Development

No branches or pull requests

3 participants