Skip to content

Commit 7474359

Browse files
raphael-proustrr0gi
authored andcommitted
Daemon: actually delay signaling exit
specifically: replace `wakeup_later` which is unpredictable with pause+wakeup which is more predicatble
1 parent 26e6648 commit 7474359

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

daemon.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ let should_run () = not !should_exit_
2727
exception ShouldExit
2828

2929
let signal_exit =
30-
let do_lwt = lazy (Lwt.wakeup_later signal_exit_lwt ()) in
31-
(* invariant: should_exit_ = (Lwt.state should_exit_lwt = Lwt.Return) *)
30+
let do_lwt = lazy (
31+
(* we can't use Lwt's wakeup_later because it doesn't always "later", it
32+
soemtimes behaves the same as plain wakeup *)
33+
Lwt.dont_wait
34+
(fun () ->
35+
Lwt.bind
36+
(Lwt.pause ())
37+
(fun () -> Lwt.wakeup signal_exit_lwt (); Lwt.return_unit))
38+
(fun exc -> log#error "signal exit: error at wakeup: %s" (Printexc.to_string exc))
39+
)
40+
in
41+
(* nearly-invariant: should_exit_ = (Lwt.state should_exit_lwt = Lwt.Return) *)
3242
fun () -> should_exit_ := true; Lazy.force do_lwt
3343

3444
(** @raise ShouldExit if [should_exit] condition is set, otherwise do nothing *)

0 commit comments

Comments
 (0)