From 38c31c3b4e0a4ce7e635db2ef75a3fd287bbeefa Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2020 14:07:12 -0700 Subject: [PATCH] Exit cleanly on panic! so the process don't limp along in a half-dead state (#9690) (#9692) automerge --- metrics/src/metrics.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/metrics/src/metrics.rs b/metrics/src/metrics.rs index dafa5e90cb..91224ec55a 100644 --- a/metrics/src/metrics.rs +++ b/metrics/src/metrics.rs @@ -5,13 +5,17 @@ use gethostname::gethostname; use lazy_static::lazy_static; use log::*; use solana_sdk::hash::hash; -use std::collections::HashMap; -use std::convert::Into; -use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender}; -use std::sync::{Arc, Barrier, Mutex, Once, RwLock}; -use std::thread; -use std::time::{Duration, Instant}; -use std::{cmp, env}; +use std::{ + collections::HashMap, + convert::Into, + sync::{ + mpsc::{channel, Receiver, RecvTimeoutError, Sender}, + Arc, Barrier, Mutex, Once, RwLock, + }, + thread, + time::{Duration, Instant}, + {cmp, env}, +}; type CounterMap = HashMap<(&'static str, u64), CounterPoint>; @@ -416,11 +420,10 @@ pub fn flush() { /// Hook the panic handler to generate a data point on each panic pub fn set_panic_hook(program: &'static str) { - use std::panic; static SET_HOOK: Once = Once::new(); SET_HOOK.call_once(|| { - let default_hook = panic::take_hook(); - panic::set_hook(Box::new(move |ono| { + let default_hook = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |ono| { default_hook(ono); let location = match ono.location() { Some(location) => location.to_string(), @@ -438,9 +441,11 @@ pub fn set_panic_hook(program: &'static str) { .to_owned(), Level::Error, ); - // Flush metrics immediately in case the process exits immediately - // upon return + // Flush metrics immediately flush(); + + // Exit cleanly so the process don't limp along in a half-dead state + std::process::exit(1); })); }); }