Skip to content

Commit 4e68f7b

Browse files
committed
Add warning when build directory lock is already held
When dune attempts to acquire the build directory lock and finds it held by another process, emit a warning message instead of silently waiting. The warning includes the PID of the lock holder (if available) and the path to the lock file, making it easier for users and AI assistants to understand why dune appears to be hanging. Signed-off-by: sabine <[email protected]>
1 parent b202280 commit 4e68f7b

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/dune_util/global_lock.ml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,42 @@ let lock ~timeout =
9999
else (
100100
let res =
101101
match timeout with
102-
| None -> Lock.lock ()
102+
| None ->
103+
(match Lock.lock () with
104+
| `Success -> `Success
105+
| `Failure ->
106+
let lock_held_by = Lock_held_by.read_lock_file () in
107+
User_warning.emit
108+
[ Pp.textf
109+
"Build directory is locked by another dune process%s. Waiting for the \
110+
lock to be released... (lock file: %s)"
111+
(match lock_held_by with
112+
| Unknown -> ""
113+
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
114+
(Path.Build.to_string lock_file)
115+
];
116+
`Failure)
103117
| Some timeout ->
118+
let warned = ref false in
104119
(match
105120
with_timeout ~timeout (fun () ->
106121
match Lock.lock () with
107122
| `Success -> `Stop
108-
| `Failure -> `Continue)
123+
| `Failure ->
124+
if not !warned
125+
then (
126+
warned := true;
127+
let lock_held_by = Lock_held_by.read_lock_file () in
128+
User_warning.emit
129+
[ Pp.textf
130+
"Build directory is locked by another dune process%s. Waiting for \
131+
the lock to be released... (lock file: %s)"
132+
(match lock_held_by with
133+
| Unknown -> ""
134+
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid)
135+
(Path.Build.to_string lock_file)
136+
]);
137+
`Continue)
109138
with
110139
| `Timed_out -> `Failure
111140
| `Success -> `Success)

0 commit comments

Comments
 (0)