mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Add panic-handlers which exit on any panic
By default, tokio-spawned worker panics will only kill the task, not the program. Due to our extensive use of panicking on invariants, we should ensure the program exits.
This commit is contained in:
@@ -118,6 +118,18 @@ mod binaries {
|
||||
async fn main() {
|
||||
use binaries::*;
|
||||
|
||||
// Override the panic handler with one which will panic if any tokio task panics
|
||||
{
|
||||
let existing = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(move |panic| {
|
||||
existing(panic);
|
||||
const MSG: &str = "exiting the process due to a task panicking";
|
||||
println!("{MSG}");
|
||||
log::error!("{MSG}");
|
||||
std::process::exit(1);
|
||||
}));
|
||||
}
|
||||
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
std::env::set_var("RUST_LOG", serai_env::var("RUST_LOG").unwrap_or_else(|| "info".to_string()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user