Skip to content

Commit b98371c

Browse files
committed
CA-418227: Handle exceptions in At_least_once_more.again
At_least_once_more is used by `consider_enabling_host_request`, which is an important function to get hosts marked as `enabled`. The purpose of this is to prevent running `consider_enabling_host` many times unnecessarily. The problem with the `again` function is that it does not handle any exception raised by the operation `f`. If an exception occurs, then the thread exists without setting `in_progress` to `false`, which prevents the operation from ever getting executied again. Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
1 parent 38ab849 commit b98371c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ocaml/xapi/at_least_once_more.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
to minimise the number of times we run the operation i.e. if a large set of changes happen we'd ideally like to
1717
just execute the function once or twice but not once per thing that changed. *)
1818

19+
module D = Debug.Make (struct let name = "at_least_once_more" end)
20+
21+
open D
22+
1923
let with_lock = Xapi_stdext_threads.Threadext.Mutex.execute
2024

2125
(** Type of the function executed in the background *)
@@ -50,7 +54,7 @@ let again (x : manager) =
5054
Thread.create
5155
(fun () ->
5256
(* Always do the operation immediately: thread is only created when work needs doing *)
53-
x.f () ;
57+
log_and_ignore_exn x.f ;
5458
while
5559
with_lock x.m (fun () ->
5660
if x.needs_doing_again then (
@@ -63,7 +67,7 @@ let again (x : manager) =
6367
)
6468
)
6569
do
66-
x.f ()
70+
log_and_ignore_exn x.f
6771
done
6872
)
6973
()

0 commit comments

Comments
 (0)