From c953f5f64d551aa1bf0c5cb71f14207bf3772a91 Mon Sep 17 00:00:00 2001 From: nkostoulas Date: Thu, 12 Dec 2019 12:22:12 +0000 Subject: [PATCH] Graceful shutdown of listener if challenge request fails --- src/coordinator.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/coordinator.rs b/src/coordinator.rs index 6147694..694096c 100644 --- a/src/coordinator.rs +++ b/src/coordinator.rs @@ -84,7 +84,7 @@ pub fn run_request( let listener_handle = ::listener::run_listener(&config.listener_host, shared_challenge.clone(), verify_tx); // run challenge request storing expected responses - ::challenger::run_challenge_request( + match ::challenger::run_challenge_request( service, clientchain, shared_challenge.clone(), @@ -94,11 +94,13 @@ pub fn run_request( time::Duration::from_secs(config.challenge_duration), config.challenge_frequency, time::Duration::from_secs(config.block_time / 2), - )?; - - listener_handle.stop(); // try stop listener service - - return Ok(Some(shared_challenge.lock().unwrap().request.txid)); + ) { + Ok(()) => return Ok(Some(shared_challenge.lock().unwrap().request.txid)), + Err(err) => { + listener_handle.stop(); // try stop listener service + Err(err) + } + } } None => Ok(None), }