From 17665689f5c06f8a6c6eddea5e1745db6a59beb9 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Mon, 2 Dec 2024 11:48:37 +0000 Subject: [PATCH] Ignore ECONNRESET on close FreeBSD returns ECONNRESET in certain (unclear) circumstances, but it does still close the FD successfully. If you care about this case, you should probably use `shutdown` instead and check for it there. Python and Ruby at least both explicitly check for and ignore this error too. --- lib_eio/tests/dscheck/unix.ml | 4 ++++ lib_eio/unix/rcfd.ml | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib_eio/tests/dscheck/unix.ml b/lib_eio/tests/dscheck/unix.ml index dc5d29f55..9e5c91a0f 100644 --- a/lib_eio/tests/dscheck/unix.ml +++ b/lib_eio/tests/dscheck/unix.ml @@ -1,3 +1,7 @@ +type error = ECONNRESET + +exception Unix_error of error * string * string + type file_descr = [`Open | `Closed] Atomic.t let make () = Atomic.make `Open diff --git a/lib_eio/unix/rcfd.ml b/lib_eio/unix/rcfd.ml index ee4455bf4..890cb462f 100644 --- a/lib_eio/unix/rcfd.ml +++ b/lib_eio/unix/rcfd.ml @@ -98,7 +98,13 @@ let get t = None let close_fd fd = - Eio.Private.Trace.with_span "close" (fun () -> Unix.close fd) + Eio.Private.Trace.with_span "close" (fun () -> + try + Unix.close fd + with Unix.Unix_error (ECONNRESET, _, _) -> + (* For FreeBSD. See https://github.com/ocaml-multicore/eio/issues/786 *) + () + ) (* Note: we could simplify this a bit by incrementing [t.ops], as [remove] does. However, that makes dscheck too slow. *)