diff --git a/CHANGES b/CHANGES index 94994bece..0322345d5 100644 --- a/CHANGES +++ b/CHANGES @@ -6,7 +6,7 @@ * Make temporary files created by Lwt_io.with_temp_dir deletable on Windows by removing the RO bit (#849, Antonin Décimo) - + * Lwt_io.establish_server* handles ECONNABORTED (#829, #830, Reynir Björnsson) ===== 5.4.0 (2020-12-16) ===== diff --git a/src/unix/lwt_io.ml b/src/unix/lwt_io.ml index 01988ed59..34fd95e75 100644 --- a/src/unix/lwt_io.ml +++ b/src/unix/lwt_io.ml @@ -1619,8 +1619,14 @@ let establish_server_generic let rec accept_loop () = let try_to_accept = - Lwt_unix.accept listening_socket >|= fun x -> - `Accepted x + Lwt.catch + (fun () -> + Lwt_unix.accept listening_socket >|= fun x -> + `Accepted x) + (function + | Unix.Unix_error (Unix.ECONNABORTED, _, _) -> + Lwt.return `Try_again + | e -> Lwt.fail e) in Lwt.pick [try_to_accept; should_stop] >>= function @@ -1646,6 +1652,8 @@ let establish_server_generic Lwt.wakeup_later notify_listening_socket_closed (); Lwt.return_unit + | `Try_again -> + accept_loop () in let server =