Fix worker are notified to stop with non_graceful shutdown

This commit is contained in:
fakeshadow 2021-04-15 16:59:01 +08:00
parent d49ecf7203
commit 788d648b6a
1 changed files with 15 additions and 31 deletions

View File

@ -381,45 +381,29 @@ impl ServerBuilder {
let notify = std::mem::take(&mut self.notify); let notify = std::mem::take(&mut self.notify);
// stop workers // stop workers
if !self.handles.is_empty() && graceful { let stop = self
let iter = self .handles
.handles .iter()
.iter() .map(move |worker| worker.1.stop(graceful))
.map(move |worker| worker.1.stop(graceful)) .collect();
.collect();
let fut = join_all(iter); rt::spawn(async move {
if graceful {
rt::spawn(async move { let _ = join_all(stop).await;
let _ = fut.await;
if let Some(tx) = completion {
let _ = tx.send(());
}
for tx in notify {
let _ = tx.send(());
}
if exit {
rt::spawn(async {
sleep(Duration::from_millis(300)).await;
System::current().stop();
});
}
});
} else {
// we need to stop system if server was spawned
if self.exit {
rt::spawn(async {
sleep(Duration::from_millis(300)).await;
System::current().stop();
});
} }
if let Some(tx) = completion { if let Some(tx) = completion {
let _ = tx.send(()); let _ = tx.send(());
} }
for tx in notify { for tx in notify {
let _ = tx.send(()); let _ = tx.send(());
} }
}
if exit {
sleep(Duration::from_millis(300)).await;
System::current().stop();
}
});
} }
ServerCommand::WorkerFaulted(idx) => { ServerCommand::WorkerFaulted(idx) => {
let mut found = false; let mut found = false;