Skip to content

Commit

Permalink
establish_server_generic: handle ECONNABORTED
Browse files Browse the repository at this point in the history
Call accept again if ECONNABORTED.
Fixes #829
  • Loading branch information
reynir authored and raphael-proust committed May 27, 2021
1 parent 84453e6 commit d74a557
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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) =====

Expand Down
12 changes: 10 additions & 2 deletions src/unix/lwt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down

0 comments on commit d74a557

Please sign in to comment.