`solana-validator exit` now uses `process::exit()` to ensure prompt termination

This commit is contained in:
Michael Vines 2021-05-06 10:39:44 -07:00
parent 640883a9a9
commit ec2b06d81d
1 changed files with 17 additions and 5 deletions

View File

@ -11,8 +11,8 @@ use {
net::SocketAddr, net::SocketAddr,
path::Path, path::Path,
sync::{Arc, RwLock}, sync::{Arc, RwLock},
thread::Builder, thread::{self, Builder},
time::SystemTime, time::{Duration, SystemTime},
}, },
}; };
@ -58,10 +58,22 @@ impl AdminRpc for AdminRpcImpl {
fn exit(&self, meta: Self::Metadata) -> Result<()> { fn exit(&self, meta: Self::Metadata) -> Result<()> {
debug!("exit admin rpc request received"); debug!("exit admin rpc request received");
// Delay exit signal until this RPC request completes, otherwise the caller of `exit` might
// receive a confusing error as the validator shuts down before a response is sent back. thread::spawn(move || {
tokio::spawn(async move { // Delay exit signal until this RPC request completes, otherwise the caller of `exit` might
// receive a confusing error as the validator shuts down before a response is sent back.
thread::sleep(Duration::from_millis(100));
warn!("validator exit requested");
meta.validator_exit.write().unwrap().exit(); meta.validator_exit.write().unwrap().exit();
// TODO: Debug why ValidatorExit doesn't always cause the validator to fully exit
// (rocksdb background processing or some other stuck thread perhaps?).
//
// If the process is still alive after five seconds, exit harder
thread::sleep(Duration::from_secs(5));
warn!("validator exit timeout");
std::process::exit(0);
}); });
Ok(()) Ok(())
} }