Julia: Windows `mv` sometimes throws IOError: EBUSY

Created on 15 Oct 2018  Â·  9Comments  Â·  Source: JuliaLang/julia

(Edit: Scroll down a few posts for new issue statement from @vtjnash).

filesystem windows

Most helpful comment

Are you seeing IOErrors also?

julia> open("f1", "w") do fd
           write(fd, "hello\n")
           mv("f1", "f2") # <== windows will always fail here
           write(fd, "goodbye\n")
           nothing
       end
ERROR: IOError: unlink: resource busy or locked (EBUSY)
Stacktrace:
 [1] uv_error at .\libuv.jl:85 [inlined]
 [2] unlink(::String) at .\file.jl:722
 [3] #rm#9(::Bool, ::Bool, ::Function, ::String) at .\file.jl:253
 [4] #rm at .\none:0 [inlined]
 [5] rename(::String, ::String) at .\file.jl:733
 [6] #mv#13 at .\file.jl:378 [inlined]
 [7] mv at .\file.jl:377 [inlined]
 [8] #11 at .\REPL[4]:3 [inlined]
 [9] #open#294(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::getfield(Main, Symbol("##11#12")), ::String, ::Vararg{String,N} where N) at .\iostream.jl:369
 [10] open(::Function, ::String, ::String) at .\iostream.jl:367
 [11] top-level scope at none:0

julia>^D

$ cat f1
hello

$ cat f2

(on posix-compliant systems, this would generally succeed, with f2 being the only file existing and containing hello\ngoodbye\n –– although on system or network failure, I assume that other permitted states are for f1 to exist empty, for f2 to be a hard-link to f1, or for f1 to contain the same contents as f2)

Ref upstream issue / proposed workaround: libuv/libuv#1981

All 9 comments

Can you post the reproducer here?

Having trouble reproducing this outside of the package, so will close for now. Will post a new issue with a standalone example once I can find one.

Are you seeing IOErrors also?

julia> open("f1", "w") do fd
           write(fd, "hello\n")
           mv("f1", "f2") # <== windows will always fail here
           write(fd, "goodbye\n")
           nothing
       end
ERROR: IOError: unlink: resource busy or locked (EBUSY)
Stacktrace:
 [1] uv_error at .\libuv.jl:85 [inlined]
 [2] unlink(::String) at .\file.jl:722
 [3] #rm#9(::Bool, ::Bool, ::Function, ::String) at .\file.jl:253
 [4] #rm at .\none:0 [inlined]
 [5] rename(::String, ::String) at .\file.jl:733
 [6] #mv#13 at .\file.jl:378 [inlined]
 [7] mv at .\file.jl:377 [inlined]
 [8] #11 at .\REPL[4]:3 [inlined]
 [9] #open#294(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::getfield(Main, Symbol("##11#12")), ::String, ::Vararg{String,N} where N) at .\iostream.jl:369
 [10] open(::Function, ::String, ::String) at .\iostream.jl:367
 [11] top-level scope at none:0

julia>^D

$ cat f1
hello

$ cat f2

(on posix-compliant systems, this would generally succeed, with f2 being the only file existing and containing hello\ngoodbye\n –– although on system or network failure, I assume that other permitted states are for f1 to exist empty, for f2 to be a hard-link to f1, or for f1 to contain the same contents as f2)

Ref upstream issue / proposed workaround: libuv/libuv#1981

I would see that from time-to-time, yeah. Thanks!

Note that this is only a problem with ios.c, this issue was fixed in Base.Filesystem.open by https://github.com/nodejs/node-v0.x-archive/issues/1449.

@vtjnash Sounds good. If there's a user with this issue, could I tell them how to use the JS instead of that file?

Sorry for any confusion, but node would run into the same problem. I don't know how to solve this, so I'm just leaving behind some breadcrumbs for anyone who wants to investigate further.

No problem. I think we've actually been able to refactor our particular package to avoid this issue a lot of the time (basically, close the file). But will edit this to reflect the new issue.

Landed upstream in libuv. So this issue is fixed if we upstream libuv changes. Well technically not fixed, but maybe improved error wise.

Was this page helpful?
0 / 5 - 0 ratings