Node: Make sure fatal errors are properly printed
This commit is contained in:
parent
602a10651c
commit
42734ee4a2
@ -4,7 +4,7 @@ val log_info: ('a, Format.formatter, unit, unit) format4 -> 'a
|
|||||||
val log_notice: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val log_notice: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val warn: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val warn: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val log_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val log_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val fatal_error: ('a, Format.formatter, unit, 'b) format4 -> 'a
|
val fatal_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
|
|
||||||
val lwt_debug: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
val lwt_debug: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
||||||
val lwt_log_info: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
val lwt_log_info: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
||||||
|
@ -180,9 +180,12 @@ let init_rpc (rpc_config: Node_config_file.rpc) node =
|
|||||||
return (Some server)
|
return (Some server)
|
||||||
|
|
||||||
let init_signal () =
|
let init_signal () =
|
||||||
let handler id = try Lwt_exit.exit id with _ -> () in
|
let handler name id = try
|
||||||
ignore (Lwt_unix.on_signal Sys.sigint handler : Lwt_unix.signal_handler_id) ;
|
fatal_error "Received the %s signal, triggering shutdown." name ;
|
||||||
ignore (Lwt_unix.on_signal Sys.sigterm handler : Lwt_unix.signal_handler_id)
|
Lwt_exit.exit id
|
||||||
|
with _ -> () in
|
||||||
|
ignore (Lwt_unix.on_signal Sys.sigint (handler "INT") : Lwt_unix.signal_handler_id) ;
|
||||||
|
ignore (Lwt_unix.on_signal Sys.sigterm (handler "TERM") : Lwt_unix.signal_handler_id)
|
||||||
|
|
||||||
let run ?verbosity ?sandbox (config : Node_config_file.t) =
|
let run ?verbosity ?sandbox (config : Node_config_file.t) =
|
||||||
Node_data_version.ensure_data_dir config.data_dir >>=? fun () ->
|
Node_data_version.ensure_data_dir config.data_dir >>=? fun () ->
|
||||||
@ -201,6 +204,7 @@ let run ?verbosity ?sandbox (config : Node_config_file.t) =
|
|||||||
lwt_log_notice "Shutting down the RPC server..." >>= fun () ->
|
lwt_log_notice "Shutting down the RPC server..." >>= fun () ->
|
||||||
Lwt_utils.may RPC_server.shutdown rpc >>= fun () ->
|
Lwt_utils.may RPC_server.shutdown rpc >>= fun () ->
|
||||||
lwt_log_notice "BYE (%d)" x >>= fun () ->
|
lwt_log_notice "BYE (%d)" x >>= fun () ->
|
||||||
|
Logging.close () >>= fun () ->
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
let process sandbox verbosity args =
|
let process sandbox verbosity args =
|
||||||
|
@ -34,7 +34,9 @@ let fork_test_network = Context.fork_test_network
|
|||||||
let datadir = ref None
|
let datadir = ref None
|
||||||
let get_datadir () =
|
let get_datadir () =
|
||||||
match !datadir with
|
match !datadir with
|
||||||
| None -> fatal_error "not initialized"
|
| None ->
|
||||||
|
fatal_error "Node not initialized" ;
|
||||||
|
Lwt_exit.exit 1
|
||||||
| Some m -> m
|
| Some m -> m
|
||||||
|
|
||||||
let init dir =
|
let init dir =
|
||||||
|
@ -16,7 +16,7 @@ module type LOG = sig
|
|||||||
val log_notice: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val log_notice: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val warn: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val warn: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val log_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val log_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val fatal_error: ('a, Format.formatter, unit, 'b) format4 -> 'a
|
val fatal_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
|
|
||||||
val lwt_debug: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
val lwt_debug: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
||||||
val lwt_log_info: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
val lwt_log_info: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
||||||
@ -56,10 +56,7 @@ module Make(S : sig val name: string end) : LOG = struct
|
|||||||
let log_notice fmt = ign_log_f ~section ~level:Lwt_log.Notice fmt
|
let log_notice fmt = ign_log_f ~section ~level:Lwt_log.Notice fmt
|
||||||
let warn fmt = ign_log_f ~section ~level:Lwt_log.Warning fmt
|
let warn fmt = ign_log_f ~section ~level:Lwt_log.Warning fmt
|
||||||
let log_error fmt = ign_log_f ~section ~level:Lwt_log.Error fmt
|
let log_error fmt = ign_log_f ~section ~level:Lwt_log.Error fmt
|
||||||
let fatal_error fmt =
|
let fatal_error fmt = ign_log_f ~section ~level:Lwt_log.Fatal fmt
|
||||||
Format.kasprintf
|
|
||||||
(fun s -> Lwt_log.ign_fatal ~section s; Lwt_exit.exit 1)
|
|
||||||
fmt
|
|
||||||
|
|
||||||
let lwt_debug fmt = log_f ~section ~level:Lwt_log.Debug fmt
|
let lwt_debug fmt = log_f ~section ~level:Lwt_log.Debug fmt
|
||||||
let lwt_log_info fmt = log_f ~section ~level:Lwt_log.Info fmt
|
let lwt_log_info fmt = log_f ~section ~level:Lwt_log.Info fmt
|
||||||
@ -203,6 +200,9 @@ let init ?(template = default_template) output =
|
|||||||
Lwt_log.default := logger ;
|
Lwt_log.default := logger ;
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
|
|
||||||
|
let close () =
|
||||||
|
Lwt_log.close !Lwt_log.default
|
||||||
|
|
||||||
type level = Lwt_log_core.level =
|
type level = Lwt_log_core.level =
|
||||||
| Debug
|
| Debug
|
||||||
(** Debugging message. They can be automatically removed by the
|
(** Debugging message. They can be automatically removed by the
|
||||||
|
@ -14,7 +14,7 @@ module type LOG = sig
|
|||||||
val log_notice: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val log_notice: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val warn: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val warn: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val log_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
val log_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
val fatal_error: ('a, Format.formatter, unit, 'b) format4 -> 'a
|
val fatal_error: ('a, Format.formatter, unit, unit) format4 -> 'a
|
||||||
|
|
||||||
val lwt_debug: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
val lwt_debug: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
||||||
val lwt_log_info: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
val lwt_log_info: ('a, Format.formatter, unit, unit Lwt.t) format4 -> 'a
|
||||||
@ -85,4 +85,6 @@ end
|
|||||||
|
|
||||||
val init: ?template:template -> Output.t -> unit Lwt.t
|
val init: ?template:template -> Output.t -> unit Lwt.t
|
||||||
|
|
||||||
|
val close: unit -> unit Lwt.t
|
||||||
|
|
||||||
val sections : string list ref
|
val sections : string list ref
|
||||||
|
@ -17,12 +17,18 @@ let () =
|
|||||||
(function
|
(function
|
||||||
| Exit -> ()
|
| Exit -> ()
|
||||||
| exn ->
|
| exn ->
|
||||||
Format.eprintf
|
|
||||||
"@[Uncaught (asynchronous) exception (%d):@ %a@]"
|
|
||||||
(Unix.getpid ())
|
|
||||||
Error_monad.pp_exn exn ;
|
|
||||||
let backtrace = Printexc.get_backtrace () in
|
let backtrace = Printexc.get_backtrace () in
|
||||||
if String.length backtrace <> 0 then
|
Logging.Node.Main.fatal_error "@[<v 2>%a%a@]"
|
||||||
Format.eprintf "\n%s" backtrace ;
|
(fun ppf exn ->
|
||||||
Format.eprintf "@." ;
|
Format.fprintf ppf
|
||||||
|
"@[Uncaught (asynchronous) exception (%d):@ %a@]"
|
||||||
|
(Unix.getpid ())
|
||||||
|
Error_monad.pp_exn exn)
|
||||||
|
exn
|
||||||
|
(fun ppf backtrace ->
|
||||||
|
if String.length backtrace <> 0 then
|
||||||
|
Format.fprintf ppf
|
||||||
|
"@,Backtrace:@, @[<h>%a@]"
|
||||||
|
Format.pp_print_text backtrace)
|
||||||
|
backtrace ;
|
||||||
Lwt.wakeup exit_wakener 1)
|
Lwt.wakeup exit_wakener 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user