diff --git a/src/node/net/RPC_server.ml b/src/node/net/RPC_server.ml index abcdfa6bd..1c6e1d4ac 100644 --- a/src/node/net/RPC_server.ml +++ b/src/node/net/RPC_server.ml @@ -183,23 +183,21 @@ let launch ?pre_hook ?post_hook ?(host="::") mode root cors_allowed_origins cors Conduit_lwt_unix.init ~src:host () >>= fun ctx -> let ctx = Cohttp_lwt_unix_net.init ~ctx () in let stop = cancelation () in - Lwt.async - (fun () -> - Lwt.catch - (fun () -> - Server.create - ~stop ~ctx ~mode - (Server.make ~callback ~conn_closed ())) - (function - | Unix.Unix_error (Unix.EADDRINUSE, "bind", _) -> - lwt_log_error "RPC server port already taken, \ - the node will be shutdown" >>= fun () -> - Lwt_exit.exit 1 - | exn -> Lwt.fail exn)) ; + let on_exn = function + | Unix.Unix_error (Unix.EADDRINUSE, "bind", _) -> + log_error "RPC server port already taken, \ + the node will be shutdown" ; + Lwt_exit.exit 1 + | Unix.Unix_error (ECONNRESET, _, _) + | Unix.Unix_error (EPIPE, _, _) -> () + | exn -> !Lwt.async_exception_hook exn + in + let server = + Server.create ~stop ~ctx ~mode ~on_exn + (Server.make ~callback ~conn_closed ()) in let shutdown () = canceler () >>= fun () -> - lwt_log_info "server not really stopped (cohttp bug)" >>= fun () -> - Lwt.return () (* server *) (* FIXME: bug in cohttp *) in + server in Lwt.return { shutdown ; root } let root_service { root } = root diff --git a/src/utils/lwt_exit.ml b/src/utils/lwt_exit.ml index f064d31e3..09481e875 100644 --- a/src/utils/lwt_exit.ml +++ b/src/utils/lwt_exit.ml @@ -16,11 +16,6 @@ let () = Lwt.async_exception_hook := (function | Exit -> () - (* BEGIN HACK - ignore error unhandled by cohttp (until PR129 is merged) *) - | Unix.Unix_error(Unix.ECONNRESET, _, _) - | Unix.Unix_error(Unix.EPIPE, _, _) -> () - (* END HACK *) | exn -> Format.eprintf "@[Uncaught (asynchronous) exception (%d):@ %a@]"