Skip to content

Commit e88ddf6

Browse files
committed
ocaml: handle unexpected error cases from the notifications pipe
The `Lwt_unix.read` is supposed to return 0 for EOF and >0 for number of bytes read. Error results from the syscall are supposed to be handled by the library. However there is evidence that an error `-1` is leaking through, so add some logging and exit the process instead of spinning. Signed-off-by: David Scott <dave@recoil.org>
1 parent 6414a3c commit e88ddf6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ OCAML_C_SRC := \
107107
OCAML_WHERE := $(shell ocamlc -where)
108108
OCAML_PACKS := cstruct cstruct-lwt io-page io-page.unix uri mirage-block \
109109
mirage-block-unix qcow unix threads lwt lwt.unix logs logs.fmt \
110-
mirage-unix prometheus-app conduit-lwt cohttp-lwt-unix
110+
mirage-unix prometheus-app conduit-lwt cohttp-lwt-unix \
111+
unix-type-representations
111112
OCAML_LDLIBS := -L $(OCAML_WHERE) \
112113
$(shell ocamlfind query cstruct)/cstruct.a \
113114
$(shell ocamlfind query cstruct)/libcstruct_stubs.a \
@@ -120,6 +121,7 @@ OCAML_LDLIBS := -L $(OCAML_WHERE) \
120121
$(shell ocamlfind query threads)/libthreadsnat.a \
121122
$(shell ocamlfind query mirage-block-unix)/libmirage_block_unix_stubs.a \
122123
$(shell ocamlfind query base)/libbase_stubs.a \
124+
$(shell ocamlfind query unix-type-representations)/libunix_type_representations_stubs.a \
123125
$(LIBEV) \
124126
-lasmrun -lunix
125127

src/lib/mirage_block_ocaml.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ let process_one t =
416416
requests and forks background threads to process all the requests. *)
417417
let serve_forever () =
418418
let buf = Bytes.make 1 '\000' in
419+
Printf.fprintf stderr "Using fd %d for I/O notifications\n%!" (Unix_representations.int_of_file_descr Protocol.request_reader);
419420
(* According to https://ocsigen.org/lwt/3.2.1/api/Lwt_unix non-blocking mode
420421
is fastest, and used by default with Unix pipes. *)
421422
let blocking = false in
@@ -429,6 +430,12 @@ let serve_forever () =
429430
Printf.fprintf stderr "Got EOF while reading signal from the pipe\n%!";
430431
exit 1
431432
end;
433+
if n < 0 then begin
434+
(* This should never happen and might indicate a bug elsewhere handling
435+
the blocking mode of the fd. *)
436+
Printf.fprintf stderr "Got %d while reading signal from the pipe\n%!" n;
437+
exit 2
438+
end;
432439
let all = Protocol.take_all () in
433440
let (_: unit Lwt.t list) = List.map process_one all in
434441
loop () in

0 commit comments

Comments
 (0)