Skip to content

Commit 1766568

Browse files
committed
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.
1 parent f26d70d commit 1766568

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib_eio/tests/dscheck/unix.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
type error = ECONNRESET
2+
3+
exception Unix_error of error * string * string
4+
15
type file_descr = [`Open | `Closed] Atomic.t
26

37
let make () = Atomic.make `Open

lib_eio/unix/rcfd.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ let get t =
9898
None
9999

100100
let close_fd fd =
101-
Eio.Private.Trace.with_span "close" (fun () -> Unix.close fd)
101+
Eio.Private.Trace.with_span "close" (fun () ->
102+
try
103+
Unix.close fd
104+
with Unix.Unix_error (ECONNRESET, _, _) ->
105+
(* For FreeBSD. See https://github.com/ocaml-multicore/eio/issues/786 *)
106+
()
107+
)
102108

103109
(* Note: we could simplify this a bit by incrementing [t.ops], as [remove] does.
104110
However, that makes dscheck too slow. *)

0 commit comments

Comments
 (0)