node: Fix bug when socket file is deleted

If the socket file is deleted while the node is running, we can no
longer quit with Ctrl-C. This is the "fix".
This commit is contained in:
Alexis Sellier 2023-02-14 21:03:45 +01:00
parent 97f7064094
commit b29ce1a222
No known key found for this signature in database
1 changed files with 5 additions and 3 deletions

View File

@ -230,13 +230,15 @@ impl<G: Signer + EcSign + 'static> Runtime<G> {
self.pool.run().unwrap();
self.reactor.join().unwrap();
control.join().unwrap()?;
daemon::kill(&daemon).ok(); // Ignore error if daemon has already exited, for whatever reason.
daemon.wait()?;
fs::remove_file(home.socket()).ok();
// If the socket file was deleted by some other process, for whatever reason,
// the control thread will not be able to join.
if fs::remove_file(home.socket()).is_ok() {
control.join().unwrap()?;
}
log::debug!(target: "node", "Node shutdown completed for {}", self.id);
Ok(())