10000 Windows: retry a file remove - a virus checker might lock files by MSoegtropIMC · Pull Request #11437 · ocaml/dune · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Windows: retry a file remove - a virus checker might lock files #11437

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

Merged
merged 3 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/changes/11437.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- On Windows, under heavy load, file delete operations can sometimes fail due to
AV programs, etc. Guard against it by retrying the operation up to 30x with a
1s waiting gap (#11437, fixes #11425, @MSoegtropIMC)
10 changes: 9 additions & 1 deletion otherlibs/stdune/src/fpath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,15 @@ let win32_unlink fn =
Unix.chmod fn 0o666;
Unix.unlink fn
with
| _ -> raise e)
| Unix.Unix_error (Unix.EACCES, _, _) ->
(* On Windows a virus scanner frequently has a lock on new executables for a short while - just retry *)
let rec retry_loop cnt =
Unix.sleep 1;
try Unix.unlink fn with
| Unix.Unix_error (Unix.EACCES, _, _) ->
if cnt > 0 then retry_loop (cnt - 1) else raise e
in
retry_loop 30)
;;

let unlink_exn = if Stdlib.Sys.win32 then win32_unlink else Unix.unlink
Expand Down
Loading
0