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:
Jon Häggblad
2022-06-29 16:47:03 +02:00
committed by GitHub
parent f2afb42daf
commit f09b984b20
18 changed files with 53 additions and 57 deletions
+1
View File
@@ -29,6 +29,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https://
- mixnode, gateway: attempting to determine reconnection backoff to persistently failing mixnode could result in a crash ([#1260])
- mixnode: the mixnode learned how to shutdown gracefully
- mixnode: listen out for SIGTERM and SIGQUIT too, making it play nicely as a system service.
- native & socks5 clients: fail early when clients try to re-init with a different gateway, which is not supported yet ([#1322])
- native & socks5 clients: rerun init will now reuse previous gateway configuration instead of failing ([#1353])
- native & socks5 clients: deduplicate big chunks of init logic
Generated
+2 -25
View File
@@ -1343,9 +1343,9 @@ dependencies = [
[[package]]
name = "dirs"
version = "3.0.2"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309"
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
dependencies = [
"dirs-sys",
]
@@ -3156,7 +3156,6 @@ dependencies = [
"rand 0.7.3",
"rocket",
"serde",
"serial_test",
"sysinfo",
"task",
"tokio",
@@ -5019,28 +5018,6 @@ dependencies = [
"yaml-rust",
]
[[package]]
name = "serial_test"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d"
dependencies = [
"lazy_static",
"parking_lot 0.11.2",
"serial_test_derive",
]
[[package]]
name = "serial_test_derive"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha-1"
version = "0.8.2"
+1 -1
View File
@@ -7,7 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dirs = "3.0"
dirs = "4.0"
futures = "0.3"
humantime-serde = "1.0"
log = "0.4"
+1 -1
View File
@@ -20,7 +20,7 @@ futures = "0.3" # bunch of futures stuff, however, now that I think about it, it
url = "2.2"
clap = "2.33.0" # for the command line arguments
dirs = "3.0" # for determining default store directories in config
dirs = "4.0"
dotenv = "0.15.0" # for obtaining environmental variables (only used for RUST_LOG for time being)
log = "0.4" # self explanatory
pretty_env_logger = "0.4" # for formatting log messages
+1 -1
View File
@@ -11,7 +11,7 @@ path = "src/lib.rs"
[dependencies]
clap = "2.33.0"
dirs = "3.0" # for determining default store directories in config
dirs = "4.0"
dotenv = "0.15.0"
futures = "0.3"
log = "0.4"
+1 -1
View File
@@ -18,4 +18,4 @@ sqlx = { version = "0.5", features = ["runtime-tokio-rustls", "chrono"]}
thiserror = "1"
tokio = { version = "1.19.1", features = [ "time" ] }
network-defaults = { path = "../network-defaults" }
network-defaults = { path = "../network-defaults" }
+1 -1
View File
@@ -19,7 +19,7 @@ bs58 = "0.4.0"
clap = { version = "3.0.10", features = ["cargo", "derive"] }
colored = "2.0"
dashmap = "4.0"
dirs = "3.0"
dirs = "4.0"
dotenv = "0.15.0"
futures = "0.3"
humantime-serde = "1.0.1"
+1 -2
View File
@@ -21,7 +21,7 @@ bs58 = "0.4.0"
clap = { version = "3.0.10", features = ["cargo", "derive"] }
colored = "2.0"
cupid = "0.6.1"
dirs = "3.0"
dirs = "4.0"
dotenv = "0.15.0"
futures = "0.3.0"
humantime-serde = "1.0"
@@ -51,7 +51,6 @@ validator-client = { path="../common/client-libs/validator-client" }
version-checker = { path="../common/version-checker" }
[dev-dependencies]
serial_test = "0.5"
tokio = { version="1.19.1", features = ["rt-multi-thread", "net", "signal", "test-util"] }
nymsphinx-types = { path = "../common/nymsphinx/types" }
+1 -1
View File
@@ -60,7 +60,7 @@ impl From<Init> for OverrideConfig {
}
}
pub(crate) async fn execute(args: &Init) {
pub(crate) fn execute(args: &Init) {
let override_config_fields = OverrideConfig::from(args.clone());
let id = &override_config_fields.id;
println!("Initialising mixnode {}...", id);
+4 -4
View File
@@ -52,7 +52,7 @@ struct OverrideConfig {
pub(crate) async fn execute(args: Cli) {
match &args.command {
Commands::Describe(m) => describe::execute(m),
Commands::Init(m) => init::execute(m).await,
Commands::Init(m) => init::execute(m),
Commands::Run(m) => run::execute(m).await,
Commands::Sign(m) => sign::execute(m),
Commands::Upgrade(m) => upgrade::execute(m),
@@ -136,7 +136,9 @@ pub(crate) fn validate_bech32_address_or_exit(address: &str) {
pub(crate) fn version_check(cfg: &Config) -> bool {
let binary_version = env!("CARGO_PKG_VERSION");
let config_version = cfg.get_version();
if binary_version != config_version {
if binary_version == config_version {
true
} else {
warn!("The mixnode binary has different version than what is specified in config file! {} and {}", binary_version, config_version);
if version_checker::is_minor_version_compatible(binary_version, config_version) {
info!("but they are still semver compatible. However, consider running the `upgrade` command");
@@ -145,7 +147,5 @@ pub(crate) fn version_check(cfg: &Config) -> bool {
error!("and they are semver incompatible! - please run the `upgrade` command before attempting `run` again");
false
}
} else {
true
}
}
+2 -2
View File
@@ -59,7 +59,7 @@ impl From<Run> for OverrideConfig {
}
}
fn show_binding_warning(address: String) {
fn show_binding_warning(address: &str) {
println!("\n##### NOTE #####");
println!(
"\nYou are trying to bind to {} - you might not be accessible to other nodes\n\
@@ -97,7 +97,7 @@ pub(crate) async fn execute(args: &Run) {
}
if special_addresses().contains(&&*config.get_listening_address().to_string()) {
show_binding_warning(config.get_listening_address().to_string());
show_binding_warning(&config.get_listening_address().to_string());
}
let mut mixnode = MixNode::new(config);
+2 -1
View File
@@ -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
View File
@@ -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");
},
}
}
+2 -2
View File
@@ -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())
@@ -12,7 +12,7 @@ edition = "2021"
[dependencies]
async-trait = { version = "0.1.51" }
clap = "2.33.0"
dirs = "3.0"
dirs = "4.0"
futures = "0.3"
ipnetwork = "0.17"
log = "0.4"
@@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dirs = "3.0"
dirs = "4.0"
log = "0.4"
pretty_env_logger = "0.4"
rocket = { version = "0.5.0-rc.2", features = ["json"] }
+1 -1
View File
@@ -17,7 +17,7 @@ rust-version = "1.56"
[dependencies]
async-trait = "0.1.52"
clap = "2.33.0"
dirs = "3.0"
dirs = "4.0"
dotenv = "0.15.0"
futures = "0.3"
humantime-serde = "1.0"
@@ -19,4 +19,4 @@ mixnet-contract-common = { path= ".../../../../common/cosmwasm-smart-contracts/m
[features]
default = []
coconut = ["coconut-interface"]
generate-ts = []
generate-ts = []