# Error EBUSY on saving JLD2 file using Julia-1.3.0-rc2

**URL:** https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228
**Category:** General Usage
**Created:** [September 27, 2019, 11:56am UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228 "2019-09-27T11:56:40Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)
#### Post date: [September 27, 2019, 11:56am UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/1 "2019-09-27T11:56:40Z")

</div>

I’m getting the following error when trying to save a file in JLD2 format on Julia-1.3.0-rc2:

```julia
$ C:/Users/blabla/AppData/Local/Julia-1.3.0-rc2/bin/julia.exe
[ Info: loading C:\Users\blabla\.julia\config\startup.jl
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.3.0-rc2.0 (2019-09-12)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

(v1.3) pkg> st
    Status `C:\Data\blabla\proj1\Project.toml`
  [5789e2e9] FileIO v1.0.7
  [033835bb] JLD2 v0.1.3

julia> using FileIO

julia> using JLD2

julia> jldopen("example.jld2", "w") do file
           file["bigdata"] = randn(5)
       end
ERROR: IOError: realpath: resource busy or locked (EBUSY)
Stacktrace:
 [1] uv_error at .\libuv.jl:97 [inlined]
 [2] realpath(::String) at .\path.jl:374
 [3] #jldopen#9(::Bool, ::Bool, ::typeof(jldopen), ::String, ::Bool, ::Bool, ::Bool, ::Type{JLD2.MmapIO}) at C:\Users\blabla\.julia\packages\JLD2\w2vgv\src\JLD2.jl:205
 [4] jldopen at C:\Users\blabla\.julia\packages\JLD2\w2vgv\src\JLD2.jl:203 [inlined] (repeats 2 times)
 [5] #jldopen#10(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(jldopen), ::String, ::String) at C:\Users\blabla\.julia\packages\JLD2\w2vgv\src\JLD2.jl:293
 [6] jldopen(::String, ::String) at C:\Users\blabla\.julia\packages\JLD2\w2vgv\src\JLD2.jl:288
 [7] #jldopen#33(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(jldopen), ::var"##7#8", ::String, ::Vararg{String,N} where N) at C:\Users\blabla\.julia\packages\JLD2\w2vgv\src\loadsave.jl:2
 [8] jldopen(::Function, ::String, ::String) at C:\Users\blabla\.julia\packages\JLD2\w2vgv\src\loadsave.jl:2
 [9] top-level scope at REPL[5]:1

```

The error does not occur on previous Julia versions up to (including) Julia-1.3.0-rc1. Any idea what has changed in rc2 that may cause this? Platform is Win7.

al

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [September 27, 2019, 12:48pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/2 "2019-09-27T12:48:30Z")

</div>

Is that a DataFrame you are trying to save? If it is then try [JDF.jl](https://github.com/xiaodaigh/JDF.jl)

---

<div class="post-metadata">

### Author: ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)
#### Post date: [September 27, 2019, 12:57pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/3 "2019-09-27T12:57:16Z")

</div>

No, it’s not a DataFrame, it’s just a regular Array:

```julia
julia> typeof(randn(5))
Array{Float64,1}

```

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [September 27, 2019, 4:07pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/4 "2019-09-27T16:07:06Z")

</div>

Does the problem happen with a fresh Julia session the first time you write to that file? Are you sure the file isn’t in use? It could be that Julia or another app fails to release a lock.

---

<div class="post-metadata">

### Author: ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)
#### Post date: [September 30, 2019, 9:57am UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/5 "2019-09-30T09:57:44Z")

</div>

Yes, exactly. The problem happens with a fresh Julia session the first time I write to that file. The file is not in use otherwise. Due to the error, however, the file stays open and I cannot delete it from Explorer until the Julia session is closed. Moreover, the file is much larger than normally (512 kB vs 1 kB) and cannot be read by `load("example.jld2")`.

FWIW, saving in text files such as

```julia
open("myfile.txt", "w") do io
          write(io, "Hello world!")
end

```

works as expected. Hence, I’m thinking whether something in JLD2/FileIO packages is not compatible with Julia-1.3.0-rc2 any longer.

Would be interesting if someone else can replicate this error.

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [September 30, 2019, 12:16pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/6 "2019-09-30T12:16:28Z")

</div>

maybe you didn’t close the io using `close(io)`

---

<div class="post-metadata">

### Author: ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)
#### Post date: [September 30, 2019, 1:13pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/7 "2019-09-30T13:13:24Z")

</div>

Thanks for the suggestion. But as far as I understand, the `jldopen(...) do ... end` construct should close the file automatically. Also note, that the code snippet works like a charm with all previous Julia versions. Only with 1.3.0-rc2 I’m getting the error. Unfortunately, I don’t see whether the problem lies most likely with JLD2 or FileIO or Julia-1.3.0-rc2 itself.

---

<div class="post-metadata">

### Author: ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)
#### Post date: [October 4, 2019, 9:55am UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/8 "2019-10-04T09:55:52Z")

</div>

Some additional information:

- The problem is still there with Julia-1.3.0-rc3. (The latest Julia version where the error does not occur is 1.3.0-rc1.)
- It seems to be specific to Windows. Code snippet above works fine on macOS with any Julia version.
- Package FileIO does not seem to be the problem. The error already occurs with only JLD2:

```julia
using JLD2
f = jldopen("example.jld2", "w")

```

produces the error message as in my initial post.

---

<div class="post-metadata">

### Author: ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)
#### Post date: [October 4, 2019, 1:32pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/9 "2019-10-04T13:32:10Z")

</div>

```julia
using JLD2
f = jldopen("example.jld2", "w")

```

works fine on my Win 10 (64) computer with Julia-1.3.0-rc3 (it worked with rc2 too), provided I am in a folder where I have writing rights. In contrast, if I change over to eg. `C:\` (which my user account is not allowed to write to) and try the same, then I get an error message.

---

<div class="post-metadata">

### Author: ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)
#### Post date: [October 4, 2019, 1:45pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/10 "2019-10-04T13:45:02Z")

</div>

Thanks for checking. So the problem seems to be specific to Windows 7. The error I get when I don’t have permission to access the file (`permission denied`) is different from the error reported above (` resource busy or locked (EBUSY)`).

Any ideas what changed in 1.3.0-rc2 with respect to file access that could make this error surface?

---

<div class="post-metadata">

### Author: ![MikeErd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikeerd/32/19159_2.png) [@MikeErd](https://discourse.julialang.org/u/MikeErd)
#### Post date: [October 7, 2019, 7:20pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/11 "2019-10-07T19:20:13Z")

</div>

Just to confirm the already posted behavior by a third person. The test has been done on two machines, to verify dependency on OS type.

Each with a completely fresh install of Julia-1.3.0-rc3.

```julia
- Starting a new shell and activating local directory ( ] + activate .).
- ] + add JLD2
- using JLD2
- f = jldopen("example.jld2", "w")
     JLDFile D:\tmp\julia_test\example.jld2 (read/write)
     (no datasets)

```

On Windows 10 Home 64bit everything works as expected.

On Windows 7 Professional 64bit, the problem occurs as described already above.

```julia
ERROR: IOError: realpath: resource busy or locked (EBUSY)

```

---

<div class="post-metadata">

### Author: ![alkoedl](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@alkoedl](https://discourse.julialang.org/u/alkoedl)
#### Post date: [October 18, 2019, 3:57pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/12 "2019-10-18T15:57:30Z")

</div>

Thanks for the confirmation @MikeErd. For the sake of completeness, the problem is still there with Julia-1.3.0-rc4.

I opened an issue at [JLD2](https://github.com/JuliaIO/JLD2.jl/issues/153#issue-504107291).

I digged a little deeper into this issue and found that within `jldopen("example.jld2", "w")` a first call `realpath("example.jld2")` (JLD2.jl line 205) works just fine, but an identical second call `realpath("example.jld2")` (JLD2.jl line 232) yields Error EBUSY. In between the two calls an MmapIO object is initialized via `io = openfile(JLD2.MmapIO, "example.jld2", true, true, true)` which seems to succeed. Does anyone have an idea how the call to `openfile()` could change the way how `realpath()` works???

I can get the same behavior by running the three commands above directly in the REPL, i.e.

```julia
julia> using JLD2

julia> realpath("example.jld2")
"C:\\Data\\example.jld2"

julia> io = JLD2.openfile(JLD2.MmapIO, "example.jld2", true, true, true)
MmapIO

julia> realpath("example.jld2")
ERROR: IOError: realpath: resource busy or locked (EBUSY)
Stacktrace:
 [1] uv_error at .\libuv.jl:97 [inlined]
 [2] realpath(::String) at .\path.jl:374
 [3] top-level scope at none:0

```

The fact that the error does not occur with Julia versions \< 1.3.0-rc2 seems to be somehow connected to [(#33116)](https://github.com/JuliaLang/julia/pull/33116) where the implementation of realpath changed considerably. Perhaps @musm or @fredrikekre know the details better and have an idea what’s going on here?

---

<div class="post-metadata">

### Author: ![jcook](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jcook/32/18211_2.png) [@jcook](https://discourse.julialang.org/u/jcook)
#### Post date: [November 2, 2019, 7:32pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/13 "2019-11-02T19:32:16Z")

</div>

I’m experiencing this problem too on v1.1 on my mac, having just updated to Catalina 10.15.1 (19B88).

```julia
julia> using JLD2

julia> @save "tmp.jld2" 0
ERROR: SystemError: realpath: No such file or directory
Stacktrace:
 [1] #systemerror#43(::Nothing, ::Function, ::Symbol, ::Bool) at ./error.jl:134
 [2] systemerror at ./error.jl:134 [inlined]
 [3] realpath(::String) at ./path.jl:367
 [4] #jldopen#9(::Bool, ::Bool, ::Function, ::String, ::Bool, ::Bool, ::Bool, ::Type{JLD2.MmapIO}) at /Users/james/.julia/packages/JLD2/KjBIK/src/JLD2.jl:205
 [5] jldopen at /Users/james/.julia/packages/JLD2/KjBIK/src/JLD2.jl:203 [inlined] (repeats 2 times)
 [6] #jldopen#10(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::String, ::String) at /Users/james/.julia/packages/JLD2/KjBIK/src/JLD2.jl:293
 [7] jldopen(::String, ::String) at /Users/james/.julia/packages/JLD2/KjBIK/src/JLD2.jl:288
 [8] #jldopen#31(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::getfield(Main, Symbol("##3#4")), ::String, ::Vararg{String,N} where N) at /Users/james/.julia/packages/JLD2/KjBIK/src/loadsave.jl:2
 [9] jldopen(::Function, ::String, ::String) at /Users/james/.julia/packages/JLD2/KjBIK/src/loadsave.jl:2
 [10] top-level scope at /Users/james/.julia/packages/JLD2/KjBIK/src/loadsave.jl:48

```

But I can’t reproduce @alkoedl’s behaviour

```julia
julia> realpath("example.jld2")
ERROR: SystemError: realpath: No such file or directory
Stacktrace:
 [1] #systemerror#43(::Nothing, ::Function, ::Symbol, ::Bool) at ./error.jl:134
 [2] systemerror at ./error.jl:134 [inlined]
 [3] realpath(::String) at ./path.jl:367
 [4] top-level scope at none:0

shell> touch example.jld2

julia> realpath("example.jld2")
"<path>/example.jld2"

julia> io = JLD2.openfile(JLD2.MmapIO, "example.jld2", true, true, true)
MmapIO

julia> realpath("example.jld2")
"<path>/example.jld2"

```

Version info

```julia
Version 1.1.2-pre.0 (2019-05-17)
release-1.1/2aee2debbb (fork: 117 commits, 330 days)

```

---

<div class="post-metadata">

### Author: ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)
#### Post date: [March 3, 2022, 7:07pm UTC](https://discourse.julialang.org/t/error-ebusy-on-saving-jld2-file-using-julia-1-3-0-rc2/29228/14 "2022-03-03T19:07:23Z")

</div>

I’m getting a similar issue:

```julia
save(joinpath("..","path","to","folder","dataframes.jld2"), "df_list", df_list)

ERROR: LoadError: IOError: realpath("..\\path\\to\\folder\\dataframes.jld2"): resource busy or locked (EBUSY)

```

when trying to save to a Box-synced directory.

The error does not occur writing to a non-cloud-synced location.

I also tried using `mv()` with Julia to move it from the non-Box location into the Box location and get

```julia
ERROR: LoadError: IOError: unlink("..\\data\\dataframes.jld2"): permission denied (EACCES)

```

Windows 10 Education version 20H2 OS build 19042.1526 and Julia 1.7.1
