Skip to content

Commit

Permalink
Handle the closing of Shards (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaenk authored and arqunis committed Jul 16, 2017
1 parent d8027d7 commit 5fd3509
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,9 @@ fn boot_shard(info: &BootInfo) -> Result<Shard> {
fn monitor_shard<H: EventHandler + 'static>(mut info: MonitorInfo<H>, 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 {
Expand Down Expand Up @@ -807,10 +809,21 @@ fn monitor_shard<H: EventHandler + 'static>(mut info: MonitorInfo<H>, 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<H: EventHandler + 'static>(info: &mut MonitorInfo<H>, handle: &Handle) {
Expand Down

0 comments on commit 5fd3509

Please sign in to comment.