Skip to content

Commit

Permalink
Avoid race conditions with recursive rm (#50842)
Browse files Browse the repository at this point in the history
If two processes attempt to recursively delete a directory at the same
time, then we can end up in a state where the initial `isdir` is `true`,
but by the time it actually deletes the directory it is already gone.
e.g.
-
https://buildkite.com/clima/climacore-ci/builds/2460#0189d254-76a9-474b-ad25-e5b16440d629/140-142
which is triggered by

https://github.com/cjdoris/PackageExtensionCompat.jl/blob/636eb5a14ddf9134d004c93f598515903af26443/src/PackageExtensionCompat.jl#L59

-
https://buildkite.com/clima/climacore-ci/builds/2457#0189c7fe-8872-40c5-9106-da2e621ff55a/139-150
which is triggered by

https://github.com/JuliaGPU/GPUCompiler.jl/blob/06e670657d7ceebc1845d7c9534a8352c33490de/src/rtlib.jl#L152

I've been conservative and only applied this when `force=true`, but
perhaps it should apply generally?

(cherry picked from commit cbd3c89)
  • Loading branch information
simonbyrne authored and IanButterworth committed Aug 25, 2023
1 parent 84b9ed0 commit 18bd99d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
try
ret = ccall(:uv_fs_rmdir, Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), C_NULL, req, path, C_NULL)
uv_fs_req_cleanup(req)
ret < 0 && uv_error("rm($(repr(path)))", ret)
if ret < 0 && !(force && ret == Base.UV_ENOENT)
uv_error("rm($(repr(path)))", ret)
end
nothing
finally
Libc.free(req)
Expand Down

0 comments on commit 18bd99d

Please sign in to comment.