From 5fd3509c8cfe25370ca4fa66a8468bd2a9679ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Israel=20Pe=C3=B1a?= Date: Sat, 15 Jul 2017 18:25:20 -0700 Subject: Handle the closing of Shards (#126) --- src/client/mod.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/client/mod.rs b/src/client/mod.rs index b80b6ac..6702a92 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -779,7 +779,9 @@ fn boot_shard(info: &BootInfo) -> Result { fn monitor_shard(mut info: MonitorInfo, handle: Handle) { handle_shard(&mut info, &handle); - loop { + let mut handle_still = HANDLE_STILL.load(Ordering::Relaxed); + + while handle_still { let mut boot_successful = false; for _ in 0..3 { @@ -807,10 +809,21 @@ fn monitor_shard(mut info: MonitorInfo, handle: Ha break; } - // The shard died: redo the cycle. + // The shard died: redo the cycle, unless client close was requested. + handle_still = HANDLE_STILL.load(Ordering::Relaxed); } - error!("Completely failed to reboot shard"); + if handle_still { + error!("Completely failed to reboot shard"); + } else { + info!("Client close was requested. Shutting down."); + + let mut shard = info.shard.lock(); + + if let Err(e) = shard.shutdown_clean() { + error!("Error shutting down shard {:?}: {:?}", shard.shard_info(), e); + } + } } fn handle_shard(info: &mut MonitorInfo, handle: &Handle) { -- cgit v1.2.3