Browse Source

faraday-lwt-unix: handle EPIPE the same way as BADFD is handled

The socket is closed for writing

This fixes an issue when a HTTP/AF + Opium server receives a request,
where the requestor closes the TCP connection before the response has
been sent completely. Note that the server in question ignores SIGPIPE
(which is then translated to an EPIPE): Sys.(set_signal epipe Signal_ignore)
Robur 1 year ago
parent
commit
182dd1a9aa
1 changed files with 2 additions and 1 deletions
  1. 2 1
      lwt_unix/faraday_lwt_unix.ml

+ 2 - 1
lwt_unix/faraday_lwt_unix.ml

@@ -13,7 +13,8 @@ let writev_of_fd fd =
         Lwt_unix.writev fd lwt_iovecs
         >|= fun n -> `Ok n)
       (function
-      | Unix.Unix_error (Unix.EBADF, "check_descriptor", _) ->
+      | Unix.Unix_error (Unix.EBADF, "check_descriptor", _)
+      | Unix.Unix_error (Unix.EPIPE, _, _) ->
         Lwt.return `Closed
       | exn ->
         Lwt.fail exn)