mixnode: handle SIGTERM (#1417)
* all: cargo upgrade dirs --workspace * mixnode: remove unused serial dependency * mixnode: handle SIGTERM and SIGQUIT on unix * mixnode: some clippy warnings * changelog: add note
This commit is contained in:
@@ -10,6 +10,7 @@ pub(crate) struct Hardware {
|
||||
crypto_hardware: Option<CryptoHardware>,
|
||||
}
|
||||
|
||||
#[allow(clippy::struct_excessive_bools)]
|
||||
#[derive(Serialize, Debug)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
pub(crate) struct CryptoHardware {
|
||||
@@ -44,9 +45,9 @@ fn hardware_from_sysinfo(crypto_hardware: Option<CryptoHardware>) -> Option<Hard
|
||||
let cores = system.cpus();
|
||||
let num_cores = cores.len();
|
||||
Some(Hardware {
|
||||
crypto_hardware,
|
||||
ram,
|
||||
num_cores,
|
||||
crypto_hardware,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
||||
+29
-11
@@ -286,17 +286,7 @@ impl MixNode {
|
||||
}
|
||||
|
||||
async fn wait_for_interrupt(&self, mut shutdown: ShutdownNotifier) {
|
||||
if let Err(e) = tokio::signal::ctrl_c().await {
|
||||
error!(
|
||||
"There was an error while capturing SIGINT - {:?}. \
|
||||
We will terminate regardless",
|
||||
e
|
||||
);
|
||||
}
|
||||
println!(
|
||||
"Received SIGINT - the mixnode will terminate now \
|
||||
(threads are not yet nicely stopped, if you see stack traces that's alright)."
|
||||
);
|
||||
wait_for_signal().await;
|
||||
|
||||
log::info!("Sending shutdown");
|
||||
shutdown.signal_shutdown().ok();
|
||||
@@ -344,3 +334,31 @@ impl MixNode {
|
||||
self.wait_for_interrupt(shutdown).await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
async fn wait_for_signal() {
|
||||
use tokio::signal::unix::{signal, SignalKind};
|
||||
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to setup SIGTERM channel");
|
||||
let mut sigquit = signal(SignalKind::quit()).expect("Failed to setup SIGQUIT channel");
|
||||
|
||||
tokio::select! {
|
||||
_ = tokio::signal::ctrl_c() => {
|
||||
log::info!("Received SIGINT");
|
||||
},
|
||||
_ = sigterm.recv() => {
|
||||
log::info!("Received SIGTERM");
|
||||
}
|
||||
_ = sigquit.recv() => {
|
||||
log::info!("Received SIGQUIT");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
async fn wait_for_signal() {
|
||||
tokio::select! {
|
||||
_ = tokio::signal::ctrl_c() => {
|
||||
log::info!("Received SIGINT");
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,14 +51,14 @@ impl SharedNodeStats {
|
||||
guard.update_time = snapshot_time;
|
||||
|
||||
guard.packets_received_since_startup += new_received;
|
||||
for (mix, count) in new_sent.iter() {
|
||||
for (mix, count) in &new_sent {
|
||||
*guard
|
||||
.packets_sent_since_startup
|
||||
.entry(mix.clone())
|
||||
.or_insert(0) += *count;
|
||||
}
|
||||
|
||||
for (mix, count) in new_dropped.iter() {
|
||||
for (mix, count) in &new_dropped {
|
||||
*guard
|
||||
.packets_explicitly_dropped_since_last_update
|
||||
.entry(mix.clone())
|
||||
|
||||
Reference in New Issue
Block a user