File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ pub mod test_utils;
33
44use futures:: channel:: mpsc:: Sender ;
55use futures:: prelude:: * ;
6- use slog:: { crit , debug, o, trace} ;
6+ use slog:: { debug, o, trace} ;
77use std:: sync:: Weak ;
88use tokio:: runtime:: { Handle , Runtime } ;
99
@@ -138,23 +138,11 @@ impl TaskExecutor {
138138 name : & ' static str ,
139139 ) {
140140 let mut shutdown_sender = self . shutdown_sender ( ) ;
141- let log = self . log . clone ( ) ;
142-
143141 if let Some ( handle) = self . handle ( ) {
144142 handle. spawn ( async move {
145143 let timer = metrics:: start_timer_vec ( & metrics:: TASKS_HISTOGRAM , & [ name] ) ;
146144 if let Err ( join_error) = task_handle. await {
147- if let Ok ( panic) = join_error. try_into_panic ( ) {
148- let message = panic. downcast_ref :: < & str > ( ) . unwrap_or ( & "<none>" ) ;
149-
150- crit ! (
151- log,
152- "Task panic. This is a bug!" ;
153- "task_name" => name,
154- "message" => message,
155- "advice" => "Please check above for a backtrace and notify \
156- the developers"
157- ) ;
145+ if let Ok ( _panic) = join_error. try_into_panic ( ) {
158146 let _ = shutdown_sender
159147 . try_send ( ShutdownReason :: Failure ( "Panic (fatal error)" ) ) ;
160148 }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use futures::TryFutureExt;
1111use lighthouse_version:: VERSION ;
1212use malloc_utils:: configure_memory_allocator;
1313use slog:: { crit, info} ;
14+ use std:: backtrace:: Backtrace ;
1415use std:: path:: PathBuf ;
1516use std:: process:: exit;
1617use task_executor:: ShutdownReason ;
@@ -528,6 +529,21 @@ fn run<E: EthSpec>(
528529
529530 let log = environment. core_context ( ) . log ( ) . clone ( ) ;
530531
532+ // Log panics properly.
533+ {
534+ let log = log. clone ( ) ;
535+ std:: panic:: set_hook ( Box :: new ( move |info| {
536+ crit ! (
537+ log,
538+ "Task panic. This is a bug!" ;
539+ "location" => info. location( ) . map( ToString :: to_string) ,
540+ "message" => info. payload( ) . downcast_ref:: <String >( ) ,
541+ "backtrace" => %Backtrace :: capture( ) ,
542+ "advice" => "Please check above for a backtrace and notify the developers" ,
543+ ) ;
544+ } ) ) ;
545+ }
546+
531547 let mut tracing_log_path: Option < PathBuf > = clap_utils:: parse_optional ( matches, "logfile" ) ?;
532548
533549 if tracing_log_path. is_none ( ) {
You can’t perform that action at this time.
0 commit comments