RPC server: use ~on_exn
This commit is contained in:
parent
ab4015b189
commit
556c965af7
@ -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 ->
|
Conduit_lwt_unix.init ~src:host () >>= fun ctx ->
|
||||||
let ctx = Cohttp_lwt_unix_net.init ~ctx () in
|
let ctx = Cohttp_lwt_unix_net.init ~ctx () in
|
||||||
let stop = cancelation () in
|
let stop = cancelation () in
|
||||||
Lwt.async
|
let on_exn = function
|
||||||
(fun () ->
|
|
||||||
Lwt.catch
|
|
||||||
(fun () ->
|
|
||||||
Server.create
|
|
||||||
~stop ~ctx ~mode
|
|
||||||
(Server.make ~callback ~conn_closed ()))
|
|
||||||
(function
|
|
||||||
| Unix.Unix_error (Unix.EADDRINUSE, "bind", _) ->
|
| Unix.Unix_error (Unix.EADDRINUSE, "bind", _) ->
|
||||||
lwt_log_error "RPC server port already taken, \
|
log_error "RPC server port already taken, \
|
||||||
the node will be shutdown" >>= fun () ->
|
the node will be shutdown" ;
|
||||||
Lwt_exit.exit 1
|
Lwt_exit.exit 1
|
||||||
| exn -> Lwt.fail exn)) ;
|
| 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 () =
|
let shutdown () =
|
||||||
canceler () >>= fun () ->
|
canceler () >>= fun () ->
|
||||||
lwt_log_info "server not really stopped (cohttp bug)" >>= fun () ->
|
server in
|
||||||
Lwt.return () (* server *) (* FIXME: bug in cohttp *) in
|
|
||||||
Lwt.return { shutdown ; root }
|
Lwt.return { shutdown ; root }
|
||||||
|
|
||||||
let root_service { root } = root
|
let root_service { root } = root
|
||||||
|
@ -16,11 +16,6 @@ let () =
|
|||||||
Lwt.async_exception_hook :=
|
Lwt.async_exception_hook :=
|
||||||
(function
|
(function
|
||||||
| Exit -> ()
|
| 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 ->
|
| exn ->
|
||||||
Format.eprintf
|
Format.eprintf
|
||||||
"@[Uncaught (asynchronous) exception (%d):@ %a@]"
|
"@[Uncaught (asynchronous) exception (%d):@ %a@]"
|
||||||
|
Loading…
Reference in New Issue
Block a user