@@ -14,7 +14,7 @@ let rec attempt_to_lock flock lock ~timeout_s =
14
14
then
15
15
let * () = Scheduler. sleep sleep_duration_s in
16
16
attempt_to_lock flock lock ~timeout_s: remaining_duration_s
17
- else Fiber. return (Ok `Failure )
17
+ else Fiber. return (Ok `Timeout )
18
18
;;
19
19
20
20
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 =
24
24
let fd =
25
25
Unix. openfile
26
26
(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 ]
28
28
0o600
29
29
in
30
30
let out = Unix. out_channel_of_descr fd in
@@ -49,25 +49,32 @@ let with_flock lock_path ~name_for_messages ~timeout_s ~f =
49
49
| Error ue ->
50
50
Unix_error.Detailed. create ue ~syscall: " flock" ~arg: " unlock"
51
51
|> Unix_error.Detailed. raise)
52
- | Ok `Failure ->
52
+ | Ok `Timeout ->
53
53
let pid = Io. read_file lock_path in
54
54
User_error. raise
55
55
~hints:
56
56
[ 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."
59
59
pid
60
60
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)
61
66
]
62
67
[ 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. "
65
70
timeout_s
71
+ pid
72
+ name_for_messages
66
73
]
67
74
| Error error ->
68
75
User_error. raise
69
76
[ 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"
71
78
name_for_messages
72
79
(Path. to_string_maybe_quoted lock_path)
73
80
(Unix. error_message error)
0 commit comments