Adds termination check during request handling loop to exit loop
@@ -83,7 +83,7 @@ where
/// Main request loop
pub fn request_loop(&mut self, should_term: Arc<AtomicBool>) -> Result<(), KmsError> {
debug!("starting handle request loop ... ");
- while self.handle_request()? {}
+ while self.handle_request(Arc::clone(&should_term))? {}
// Only happens when we received a PoisonPillMsg, so tell the outer
// thread to terminate.
should_term.swap(true, Ordering::Relaxed);
@@ -91,7 +91,11 @@ where
}
/// Handle an incoming request from the validator
- fn handle_request(&mut self) -> Result<bool, KmsError> {
+ fn handle_request(&mut self, should_term: Arc<AtomicBool>) -> Result<bool, KmsError> {
+ if should_term.load(Ordering::Relaxed) {
+ info!("terminate signal received");
+ return Ok(false)
+ }
debug!("started handling request ... ");
let response = match Request::read(&mut self.connection)? {
Request::SignProposal(req) => self.sign(req)?,
