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 warn: ('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_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)
|
||||
|
||||
let init_signal () =
|
||||
let handler id = try Lwt_exit.exit id with _ -> () in
|
||||
ignore (Lwt_unix.on_signal Sys.sigint handler : Lwt_unix.signal_handler_id) ;
|
||||
ignore (Lwt_unix.on_signal Sys.sigterm handler : Lwt_unix.signal_handler_id)
|
||||
let handler name id = try
|
||||
fatal_error "Received the %s signal, triggering shutdown." name ;
|
||||
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) =
|
||||
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_utils.may RPC_server.shutdown rpc >>= fun () ->
|
||||
lwt_log_notice "BYE (%d)" x >>= fun () ->
|
||||
Logging.close () >>= fun () ->
|
||||
return ()
|
||||
|
||||
let process sandbox verbosity args =
|
||||
|
@ -34,7 +34,9 @@ let fork_test_network = Context.fork_test_network
|
||||
let datadir = ref None
|
||||
let get_datadir () =
|
||||
match !datadir with
|
||||
| None -> fatal_error "not initialized"
|
||||
| None ->
|
||||
fatal_error "Node not initialized" ;
|
||||
Lwt_exit.exit 1
|
||||
| Some m -> m
|
||||
|
||||
let init dir =
|
||||
|
@ -16,7 +16,7 @@ module type LOG = sig
|
||||
val log_notice: ('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 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_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 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 fatal_error fmt =
|
||||
Format.kasprintf
|
||||
(fun s -> Lwt_log.ign_fatal ~section s; Lwt_exit.exit 1)
|
||||
fmt
|
||||
let fatal_error fmt = ign_log_f ~section ~level:Lwt_log.Fatal 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
|
||||
@ -203,6 +200,9 @@ let init ?(template = default_template) output =
|
||||
Lwt_log.default := logger ;
|
||||
Lwt.return_unit
|
||||
|
||||
let close () =
|
||||
Lwt_log.close !Lwt_log.default
|
||||
|
||||
type level = Lwt_log_core.level =
|
||||
| Debug
|
||||
(** 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 warn: ('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_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 close: unit -> unit Lwt.t
|
||||
|
||||
val sections : string list ref
|
||||
|
@ -17,12 +17,18 @@ let () =
|
||||
(function
|
||||
| Exit -> ()
|
||||
| exn ->
|
||||
Format.eprintf
|
||||
"@[Uncaught (asynchronous) exception (%d):@ %a@]"
|
||||
(Unix.getpid ())
|
||||
Error_monad.pp_exn exn ;
|
||||
let backtrace = Printexc.get_backtrace () in
|
||||
if String.length backtrace <> 0 then
|
||||
Format.eprintf "\n%s" backtrace ;
|
||||
Format.eprintf "@." ;
|
||||
Logging.Node.Main.fatal_error "@[<v 2>%a%a@]"
|
||||
(fun ppf exn ->
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user