-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
rm(..., recursive=true) "directory not empty" errors #34700
Comments
Out of curiosity, what happens if you try running |
Also, can you post the output of |
I tried it with |
|
Running into the same issue |
Turns out that |
I don't think that was the case in my original issue, where simply running the |
running into same issue julia 1.6 intel macbook m1 |
Windows does not delete files when you |
That talks about open files. I don't think that is the case in the other scenarios here. |
If you are running a virus scanner, many of those causes deletion errors without the trick above |
I am seeing this error again in Julia 1.8. |
Seems like we should probably implement the trick from pidfiles and/or put some retry logic in on Windows. Annoying but better than being unreliable at this. |
The pidfiles trick gets a bit harder if you are dealing with directories, since you need to attempt to move all of the files to the parent while deleting them and then the directory. Or delay the directory deletion for some random later time (maybe with fsnotify?) |
The stupidest thing we could do is retry a few times optionally with an increasing backoff delay. |
Can we call a Win32 function on Windows and let the OS deal with it? |
I am uncertain if we load shell32.dll (I think libuv does), but it should just be delegating to our same underlying Win32 calls |
For what is worth, I recently had this problem outside of Julia. On an x86_64 linux system I got $ rm -rf directory/
rm: cannot remove 'directory/.spack-env': Directory not empty What I believe has happened in my case is that a rogue What I want to say here is that if anything Julia isn't any worse than Coreutils |
@giordano, we aren't talking about rogue processes here. Even if the directory is completely static, Julia's |
I've been facing this issue recently in a corporate windows environment. I'm confident it's antivirus/security related. I've experienced it in two places:
Not sure if there is anything I can do to help/expedite resolution/workaround, but I'd certainly offer to test any potential solutions. |
Does anybody have any update or workaround for this issue? Also, does anybody know if this PR potentially helps or interacts: #50842 ? In my personal testing and use cases, I still (although inconsistently....makes me think potentially some race condition) seem to be getting the issue, but potentially the PR didn't go far enough as it only covered the force=true only cases? |
@mestinso, I don't think this has anything to do with #50842. The issue here is that a single process has trouble recursively deleting a directory on Windows, apparently because of some quirks in the Windows filesystem. I still think we should try to just call |
Just a heads up, I'm seeing this issue running Julia 1.10 on Linux CentOs 7. |
@p-foresman, without more information, I’m skeptical it’s the same issue. (There are legitimate reasons why you might get “directory not empty” errors, and the specific issue here seems Windows-specific thus far.) |
Not sure this is related but I got this on Windows
when I had another Windows Julia session opened that kept the shared library in that folder open in the process. |
Yeah, unfortunately, Windows just won't let you delete something that's opened by some other process. |
See also this stackoverflow thread — you can apparently mark the file to be deleted on the next reboot 😆 . |
Amazing 😂😭 |
Often you can just rename it too, as the actual lock preventing deletion is often on the name, not the file handle |
I'm wondering if this is related to rm(absolute_root; force=true, recursive=true) (xref: JuliaDocs/DemoCards.jl#160) Full output from the Github [ Info: Clean up DemoCards build dir: "..\figures"
ERROR: LoadError: IOError: rm("D:\\a\\Nagy_2023_SwellMigration\\Nagy_2023_SwellMigration\\site\\src\\figures\\Notebooks"): resource busy or locked (EBUSY)
Stacktrace:
[1] uv_error
@ Base .\libuv.jl:100 [inlined]
[2] rm(path::String; force::Bool, recursive::Bool)
@ Base.Filesystem .\file.jl:307
[3] rm(path::String; force::Bool, recursive::Bool)
@ Base.Filesystem .\file.jl:294
[4] rm
@ .\file.jl:273 [inlined]
[5] (::DemoCards.var"#113#118"{String, String, String, String})()
@ DemoCards C:\Users\runneradmin\.julia\packages\DemoCards\Oz6IE\src\generate.jl:209
[6] top-level scope
@ D:\a\Nagy_2023_SwellMigration\Nagy_2023_SwellMigration\site\make.jl:47
in expression starting at D:\a\Nagy_2023_SwellMigration\Nagy_2023_SwellMigration\site\make.jl:47
GKS: could not find font bold.ttf
Error: Process completed with exit code 1. |
@tlnagy if calling The issue here is recursive deletion of directories where nothing is locked/busy, but it still fails because of a race condition in the Windows filesystem. |
FWIW, the race condition usually is not in the Windows filesystem, but rather that the NT kernel currently makes it impossible to implement a reliable virus scanner, but everyone runs a virus scanner anyways. |
Same issue in Rust: rust-lang/rust#29497
|
That functionality hasn't been present in But the rust stdlib now uses the POSIX_SEMANTICS flag, when supported by the OS and filesystem, to probably fix this: rust-lang/rust@5ab67bf#diff-e8df55f38a9a224cf1cfd40e6c535535aa66e8073cc8d9b959308659ba1de1f9R564-R592 Seems like at least half of this bug might be in the implementation of DeleteFile on Win32 being bad, so that calling the underlying API instead is a bit more reliable? (DeleteFile sets the FILE_SHARE_DELETE flag, which delays deletion, while the underlying API can be called without that flag) FWIW, this has all been known for at least a few years, but waiting for some developer to care enough about Windows to use the new kernel APIs: libuv/libuv#3839 |
The Rust implementation of that change was here rust-lang/rust@5ab67bf#diff-e8df55f38a9a224cf1cfd40e6c535535aa66e8073cc8d9b959308659ba1de1f9R572-R577 |
I was encountering this "directory not empty" error with pkg Switching to Julia 1.11 fixed it! currently 1.11.0-alpha2+0.x64.w64.mingw32 possibly fixed by #53456 (though I did not confirm if this commit is in the 1.11 build) |
I was trying to delete my Anaconda installation, which is a huge directory tree (10000+ files), with
and I keep getting
SystemError .... rmdir: Directory not empty
errors. However, if I check that directory, I find that it is indeed empty. Indeed, if I runrm(Conda.ROOTENV, recursive=true)
again, then it succeeds in deleting that directory, but then proceeds to give me a similar error with another directory, ad nauseam.For example (apologies for the screenshot):
It looks like there is some kind of race condition in the recursive
rm
, where it empties the directory, but Windows doesn't realize that the files are gone when it tries tormdir
.(To reproduce, add the Conda.jl package, make sure it installs Anaconda by running
Conda.add("jupyter")
, and then try runningrm
as above. I'm seeming this in a Windows VM, but I saw the same problem on a student's machine earlier today, both with Julia 1.3.1.)The text was updated successfully, but these errors were encountered: