Skip to content

Commit

Permalink
Ignore ECONNRESET on close
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
talex5 committed Dec 2, 2024
1 parent f26d70d commit 1766568
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib_eio/tests/dscheck/unix.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib_eio/unix/rcfd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)
Expand Down

0 comments on commit 1766568

Please sign in to comment.