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 <kcired@pm.me>
This commit is contained in:
Derick Eddington 2024-07-17 18:58:01 -07:00 committed by cloudhead
parent 123f7eb6bb
commit 6f8d75a00d
No known key found for this signature in database
1 changed files with 15 additions and 4 deletions

View File

@ -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() {
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;
}
}
});