Skip to content

Commit 5712586

Browse files
committed
wip
1 parent 020b2ec commit 5712586

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/dune_pkg/flock.ml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let rec attempt_to_lock flock lock ~timeout_s =
1414
then
1515
let* () = Scheduler.sleep sleep_duration_s in
1616
attempt_to_lock flock lock ~timeout_s:remaining_duration_s
17-
else Fiber.return (Ok `Failure)
17+
else Fiber.return (Ok `Timeout)
1818
;;
1919

2020
let with_flock lock_path ~name_for_messages ~timeout_s ~f =
@@ -24,7 +24,7 @@ let with_flock lock_path ~name_for_messages ~timeout_s ~f =
2424
let fd =
2525
Unix.openfile
2626
(Path.to_string lock_path)
27-
[ Unix.O_CREAT; O_WRONLY; O_SHARE_DELETE; Unix.O_CLOEXEC ]
27+
[ Unix.O_CREAT; O_WRONLY; O_SHARE_DELETE; O_CLOEXEC ]
2828
0o600
2929
in
3030
let out = Unix.out_channel_of_descr fd in
@@ -49,25 +49,32 @@ let with_flock lock_path ~name_for_messages ~timeout_s ~f =
4949
| Error ue ->
5050
Unix_error.Detailed.create ue ~syscall:"flock" ~arg:"unlock"
5151
|> Unix_error.Detailed.raise)
52-
| Ok `Failure ->
52+
| Ok `Timeout ->
5353
let pid = Io.read_file lock_path in
5454
User_error.raise
5555
~hints:
5656
[ Pp.textf
57-
"Another dune instance (pid %s) has locked the %s. If this is happening \
58-
in error, make sure to terminate that instance and re-run the command."
57+
"Another instance of dune (pid %s) currently holds the %S lock. If this \
58+
is unexpected, terminate that process and re-run the command."
5959
pid
6060
name_for_messages
61+
; Pp.textf
62+
"As a last resort, if the other instance of dune (pid %s) is no longer \
63+
running, manually delete the lock file %s."
64+
pid
65+
(Path.to_string_maybe_quoted lock_path)
6166
]
6267
[ Pp.textf
63-
"Couldn't acquire %s lock after %f seconds"
64-
name_for_messages
68+
"Timed out after %f seconds while waiting for another instance of dune \
69+
(pid %s) to release the lock on the resource %S."
6570
timeout_s
71+
pid
72+
name_for_messages
6673
]
6774
| Error error ->
6875
User_error.raise
6976
[ Pp.textf
70-
"Failed to get a lock for the %s at %s: %s"
77+
"Failed to get a lock for the resource %S with lock file %s: %s"
7178
name_for_messages
7279
(Path.to_string_maybe_quoted lock_path)
7380
(Unix.error_message error)

0 commit comments

Comments
 (0)