فهرست منبع

darkirc: set a panic hook so when panic is invoked in a multi-threaded app it just straight up aborts the node immediately.

darkfi 1 سال پیش
والد
کامیت
0ee4e998eb
2فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 9 0
      bin/darkirc/src/main.rs
  2. 2 2
      bin/darkwallet/src/main.rs

+ 9 - 0
bin/darkirc/src/main.rs

@@ -59,6 +59,12 @@ mod rpc;
 /// Settings utilities
 mod settings;
 
+fn panic_hook(panic_info: &std::panic::PanicInfo) {
+    error!("panic occurred: {panic_info}");
+    error!("{}", std::backtrace::Backtrace::force_capture().to_string());
+    std::process::abort()
+}
+
 #[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
 #[serde(default)]
 #[structopt(name = "darkirc", about = cli_desc!())]
@@ -174,6 +180,9 @@ impl DarkIrc {
 
 async_daemonize!(realmain);
 async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
+    // Abort the application on panic right away
+    std::panic::set_hook(Box::new(panic_hook));
+
     if args.gen_chacha_keypair {
         let secret = crypto_box::SecretKey::generate(&mut OsRng);
         let public = secret.public_key();

+ 2 - 2
bin/darkwallet/src/main.rs

@@ -78,11 +78,11 @@ pub type ExecutorPtr = Arc<smol::Executor<'static>>;
 fn panic_hook(panic_info: &std::panic::PanicInfo) {
     error!("panic occurred: {panic_info}");
     error!("{}", std::backtrace::Backtrace::force_capture().to_string());
-    std::process::exit(1);
+    std::process::abort()
 }
 
 fn main() {
-    // Exit the application on panic right away
+    // Abort the application on panic right away
     std::panic::set_hook(Box::new(panic_hook));
 
     logger::setup_logging();