Skip to content

Commit

Permalink
fix issue where updater thread stops other threads
Browse files Browse the repository at this point in the history
  • Loading branch information
digizeph committed Aug 14, 2024
1 parent 1382a58 commit b6361f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bgpkit-broker"
version = "0.7.2"
version = "0.7.3"
edition = "2021"
authors = ["Mingwei Zhang <[email protected]>"]
readme = "README.md"
Expand Down
16 changes: 7 additions & 9 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down

0 comments on commit b6361f7

Please sign in to comment.