When shutting down, wait no more than 5 seconds for connections to close

This commit is contained in:
Mike Dilger 2024-07-14 10:28:15 +12:00
parent d1333bfe82
commit e3ec1cac57

View File

@ -148,10 +148,12 @@ async fn main() -> Result<(), Error> {
if num_connections != 0 {
log::info!(target: "Server", "Waiting for {num_connections} websockets to shutdown...");
// We will check if all clients have shutdown every 25ms
let interval = tokio::time::interval(Duration::from_millis(25));
// We will check if all clients have shutdown every 50ms
let interval = tokio::time::interval(Duration::from_millis(50));
tokio::pin!(interval);
let mut ms = 0;
while num_connections != 0 {
// If we get another shutdown signal, stop waiting for websockets
tokio::select! {
@ -165,6 +167,11 @@ async fn main() -> Result<(), Error> {
break;
},
_instant = interval.tick() => {
ms += 50;
if ms > 5_000 {
log::info!(target: "Server", "Some connections were hung.");
break;
}
num_connections = GLOBALS.num_connections.load(Ordering::Relaxed);
continue;
}