Skip to content

Commit 32311dd

Browse files
authored
Improve RRD robustness (#6420)
Two small commits to improve RRD daemons.
2 parents ece6444 + a9d3fc4 commit 32311dd

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ let monitor_write_loop writers =
543543
) ;
544544
Thread.delay !Rrdd_shared.timeslice
545545
with e ->
546-
debug
546+
warn
547547
"Monitor/write thread caught an exception. Pausing for 10s, \
548548
then restarting: %s"
549549
(Printexc.to_string e) ;

ocaml/xcp-rrdd/lib/transport/file/rrd_file_writer.ml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
type local_id = {path: string; shared_page_count: int}
1616

17+
let finally f finally = Fun.protect ~finally f
18+
1719
module File = struct
1820
let page_size = 4096
1921

@@ -29,14 +31,17 @@ module File = struct
2931
let init {path; shared_page_count} =
3032
let size = shared_page_count * page_size in
3133
let fd = Unix.openfile path [Unix.O_RDWR; Unix.O_CREAT] 0o600 in
32-
let mapping =
33-
Bigarray.(
34-
array1_of_genarray @@ Unix.map_file fd char c_layout true [|size|]
34+
finally
35+
(fun () ->
36+
let mapping =
37+
Bigarray.(
38+
array1_of_genarray @@ Unix.map_file fd char c_layout true [|size|]
39+
)
40+
in
41+
let cstruct = Cstruct.of_bigarray mapping in
42+
(path, cstruct)
3543
)
36-
in
37-
Unix.close fd ;
38-
let cstruct = Cstruct.of_bigarray mapping in
39-
(path, cstruct)
44+
(fun () -> Unix.close fd)
4045

4146
let cleanup _ path _ = Unix.unlink path
4247

0 commit comments

Comments
 (0)