From 6f8d75a00daac96ee4b375b4a7e93cfb8988820c Mon Sep 17 00:00:00 2001 From: Derick Eddington Date: Wed, 17 Jul 2024 18:58:01 -0700 Subject: [PATCH] node: Fix "signals" thread Fix "signals" thread to continue upon other signals. Otherwise, previously, when one of the non-shutdown signals was received, that would cause the "signals" thread to finish, but then a subsequent signal that should cause shutdown would not because the thread no longer existed to do so. E.g. when SIGHUP or SIGWINCH was received first and ignored and then SIGTERM or SIGINT was received next, the program should still be shutdown, but it wouldn't be. This is now fixed by simply looping to continue handling subsequent signals. Logging is now done for: - Receiving of SIGHUP, at log level `debug`, because the default action for that signal would be to terminate the process but that is not done by `radicle_signals`. Someone sending that signal might want to debug why the process isn't being terminated. - Disconnection of the signal-notifications channel, at log level `warn`, because, even though that should be impossible, if it somehow occurs then a warning is warranted. Logging is not done for receiving of SIGWINCH, because the default action for that signal would be to ignore it, which is what `radicle-node` does. A wildcard pattern is not used in the match arms, so that any future changes to the `Signal` variants will require reviewing their handling in the "signals" thread. Signed-off-by: Derick Eddington --- radicle-node/src/runtime.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/radicle-node/src/runtime.rs b/radicle-node/src/runtime.rs index dae86c08..7f8ca3de 100644 --- a/radicle-node/src/runtime.rs +++ b/radicle-node/src/runtime.rs @@ -289,10 +289,21 @@ impl Runtime { let handle = self.handle.clone(); || control::listen(self.control, handle) }); - let _signals = thread::spawn(&self.id, "signals", move || { - if let Ok(Signal::Terminate | Signal::Interrupt) = self.signals.recv() { - log::info!(target: "node", "Termination signal received; shutting down.."); - self.handle.shutdown().ok(); + let _signals = thread::spawn(&self.id, "signals", move || loop { + match self.signals.recv() { + Ok(Signal::Terminate | Signal::Interrupt) => { + log::info!(target: "node", "Termination signal received; shutting down.."); + self.handle.shutdown().ok(); + break; + } + Ok(Signal::Hangup) => { + log::debug!(target: "node", "Hangup signal (SIGHUP) received; ignoring.."); + } + Ok(Signal::WindowChanged) => {} + Err(e) => { + log::warn!(target: "node", "Signal notifications channel error: {e}"); + break; + } } });