From b6361f75bb5387716216067837dd54f19ef3550c Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Wed, 14 Aug 2024 00:39:40 -0700 Subject: [PATCH] fix issue where updater thread stops other threads --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- src/cli/main.rs | 16 +++++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc3cfdd..45fdf22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## v0.7.3 - 2024-08-14 + +### Hotfix + +* fix an issue where the main thread waits for updater thread and never starts the API thread + ## v0.7.2 - 2024-08-13 ### Highlights diff --git a/Cargo.toml b/Cargo.toml index f848df7..75dae41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bgpkit-broker" -version = "0.7.2" +version = "0.7.3" edition = "2021" authors = ["Mingwei Zhang "] readme = "README.md" diff --git a/src/cli/main.rs b/src/cli/main.rs index 05948e6..9aec859 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -398,10 +398,16 @@ fn main() { } } + // set global panic hook so that child threads (updater or api) will crash the process should it encounter a panic + std::panic::set_hook(Box::new(|panic_info| { + eprintln!("Global panic hook: {:?}", panic_info); + exit(1) + })); + if !no_update { // starting a new dedicated thread to periodically fetch new data from collectors let path = db_path.clone(); - let handle = std::thread::spawn(move || { + std::thread::spawn(move || { let rt = get_tokio_runtime(); let collectors = load_collectors().unwrap(); @@ -427,14 +433,6 @@ fn main() { } }); }); - - // the only way the code reaches here is that somehow the `update_database`, which - // fetches from the collectors and inserting into databases failed. in this case, - // we will panic and exit the program. - handle.join().unwrap(); - // just in case the thread somehow escaped the loop with a success code, we will - // still exit the program by panicking here. - panic!("update_database thread exited unexpectedly"); } if !no_api {