Do not do double check on connection num when entering graceful shutdown

This commit is contained in:
fakeshadow 2021-04-02 02:58:55 +08:00
parent 6d66cfb06a
commit 4fe44c5263
1 changed files with 6 additions and 12 deletions

View File

@ -356,18 +356,12 @@ impl Future for ServerWorker {
return Poll::Ready(());
} else if graceful {
self.shutdown(false);
let num = num_connections();
if num != 0 {
info!("Graceful worker shutdown, {} connections", num);
self.state = WorkerState::Shutdown(
Box::pin(sleep(Duration::from_secs(1))),
Box::pin(sleep(self.config.shutdown_timeout)),
Some(result),
);
} else {
let _ = result.send(true);
return Poll::Ready(());
}
info!("Graceful worker shutdown, {} connections", num);
self.state = WorkerState::Shutdown(
Box::pin(sleep(Duration::from_secs(1))),
Box::pin(sleep(self.config.shutdown_timeout)),
Some(result),
);
} else {
info!("Force shutdown worker, {} connections", num);
self.shutdown(true);