Skip to content

Commit 3e24f22

Browse files
committed
Warn users when RPC connection retry loop is triggered
When dune attempts to forward a build request to an existing dune process but cannot establish an RPC connection, it silently retries indefinitely. This adds a warning message to inform users what is happening and how to resolve the issue by deleting _build/.lock if no other dune process is actually running. Signed-off-by: Sabine Schmaltz <[email protected]>
1 parent 172ebb1 commit 3e24f22

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bin/rpc/rpc_common.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,31 @@ let establish_connection_exn () =
7777
let establish_connection_with_retry () =
7878
let open Fiber.O in
7979
let pause_between_retries_s = 0.2 in
80+
let warned = ref false in
8081
let rec loop () =
8182
establish_connection ()
8283
>>= function
8384
| Ok x -> Fiber.return x
8485
| Error _ ->
86+
if not !warned
87+
then (
88+
warned := true;
89+
let lock_file = Path.Build.(relative root ".lock") in
90+
let lock_held_by = Dune_util.Global_lock.Lock_held_by.read_lock_file () in
91+
let pid_suffix =
92+
match lock_held_by with
93+
| Dune_util.Global_lock.Lock_held_by.Unknown -> ""
94+
| Pid_from_lockfile pid -> sprintf " (pid: %d)" pid
95+
in
96+
User_warning.emit
97+
[ Pp.textf
98+
"Another dune instance%s is currently running. Waiting for it to finish..."
99+
pid_suffix
100+
; Pp.textf
101+
"If you're certain no other dune process is running, you can resolve this by \
102+
deleting: %s"
103+
(Path.Build.to_string lock_file)
104+
]);
85105
let* () = Dune_engine.Scheduler.sleep ~seconds:pause_between_retries_s in
86106
loop ()
87107
in

0 commit comments

Comments
 (0)