Skip to content

Commit cbd3c89

Browse files
authored
Avoid race conditions with recursive rm (#50842)
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?
1 parent 2d24155 commit cbd3c89

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

base/file.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ function rm(path::AbstractString; force::Bool=false, recursive::Bool=false)
303303
try
304304
ret = ccall(:uv_fs_rmdir, Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Cstring, Ptr{Cvoid}), C_NULL, req, path, C_NULL)
305305
uv_fs_req_cleanup(req)
306-
ret < 0 && uv_error("rm($(repr(path)))", ret)
306+
if ret < 0 && !(force && ret == Base.UV_ENOENT)
307+
uv_error("rm($(repr(path)))", ret)
308+
end
307309
nothing
308310
finally
309311
Libc.free(req)

0 commit comments

Comments
 (0)