From 056252a430078635f589d9ad6727745e12c3b13f Mon Sep 17 00:00:00 2001 From: sksat Date: Wed, 26 Oct 2022 11:30:54 +0900 Subject: [PATCH] exit process on panic in thread for restart container --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.rs b/src/main.rs index 1d4c5cb..6e14a04 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,13 @@ async fn main() -> Result<(), Box> { // install global collector configured based on RUST_LOG env var. tracing_subscriber::fmt::init(); + // cause process exit on panic in thread for restart container + let orig_hook = std::panic::take_hook(); + std::panic::set_hook(Box::new(move |panic_info| { + orig_hook(panic_info); + std::process::exit(1); + })); + let opt = Opt::from_args(); info!("start app");