From bd39ab93654cf448df13a98f64a39134f5c66991 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 5 Mar 2019 19:00:26 -0800 Subject: [PATCH] Clean up exit signal handling --- core/src/local_vote_signer_service.rs | 2 +- vote-signer/src/bin/main.rs | 3 +-- vote-signer/src/rpc.rs | 18 ++++-------------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/core/src/local_vote_signer_service.rs b/core/src/local_vote_signer_service.rs index 93b75255e..e53e0f815 100644 --- a/core/src/local_vote_signer_service.rs +++ b/core/src/local_vote_signer_service.rs @@ -34,7 +34,7 @@ impl LocalVoteSignerService { let thread = Builder::new() .name("solana-vote-signer".to_string()) .spawn(move || { - let service = VoteSignerRpcService::new(addr, thread_exit); + let service = VoteSignerRpcService::new(addr, &thread_exit); service.join().unwrap(); }) .unwrap(); diff --git a/vote-signer/src/bin/main.rs b/vote-signer/src/bin/main.rs index c87548cfd..400967115 100644 --- a/vote-signer/src/bin/main.rs +++ b/vote-signer/src/bin/main.rs @@ -31,10 +31,9 @@ fn main() -> Result<(), Box> { let exit = Arc::new(AtomicBool::new(false)); let service = VoteSignerRpcService::new( SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port), - exit, + &exit, ); service.join().unwrap(); - Ok(()) } diff --git a/vote-signer/src/rpc.rs b/vote-signer/src/rpc.rs index df47c96c5..5c6bbb477 100644 --- a/vote-signer/src/rpc.rs +++ b/vote-signer/src/rpc.rs @@ -14,13 +14,12 @@ use std::time::Duration; pub struct VoteSignerRpcService { thread_hdl: JoinHandle<()>, - exit: Arc, } impl VoteSignerRpcService { - pub fn new(rpc_addr: SocketAddr, exit: Arc) -> Self { + pub fn new(rpc_addr: SocketAddr, exit: &Arc) -> Self { let request_processor = LocalVoteSigner::default(); - let exit_ = exit.clone(); + let exit = exit.clone(); let thread_hdl = Builder::new() .name("solana-vote-signer-jsonrpc".to_string()) .spawn(move || { @@ -40,22 +39,13 @@ impl VoteSignerRpcService { warn!("JSON RPC service unavailable: unable to bind to RPC port {}. \nMake sure this port is not already in use by another application", rpc_addr.port()); return; } - while !exit_.load(Ordering::Relaxed) { + while !exit.load(Ordering::Relaxed) { sleep(Duration::from_millis(100)); } server.unwrap().close(); }) .unwrap(); - Self { thread_hdl, exit } - } - - pub fn exit(&self) { - self.exit.store(true, Ordering::Relaxed); - } - - pub fn close(self) -> thread::Result<()> { - self.exit(); - self.join() + Self { thread_hdl } } pub fn join(self) -> thread::Result<()> {