Fix busy loop
This commit is contained in:
parent
10d13b194b
commit
7d5070c57d
1 changed files with 9 additions and 4 deletions
13
src/https.rs
13
src/https.rs
|
@ -56,9 +56,16 @@ pub async fn serve_https(
|
||||||
let mut connections = FuturesUnordered::new();
|
let mut connections = FuturesUnordered::new();
|
||||||
|
|
||||||
while !*must_exit.borrow() {
|
while !*must_exit.borrow() {
|
||||||
|
let wait_conn_finished = async {
|
||||||
|
if connections.is_empty() {
|
||||||
|
futures::future::pending().await
|
||||||
|
} else {
|
||||||
|
connections.next().await
|
||||||
|
}
|
||||||
|
};
|
||||||
let (socket, remote_addr) = select! {
|
let (socket, remote_addr) = select! {
|
||||||
a = tcp.accept() => a?,
|
a = tcp.accept() => a?,
|
||||||
_ = connections.next() => continue,
|
_ = wait_conn_finished => continue,
|
||||||
_ = must_exit.changed() => continue,
|
_ = must_exit.changed() => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -105,9 +112,7 @@ pub async fn serve_https(
|
||||||
drop(tcp);
|
drop(tcp);
|
||||||
|
|
||||||
info!("HTTPS server shutting down, draining remaining connections...");
|
info!("HTTPS server shutting down, draining remaining connections...");
|
||||||
while !connections.is_empty() {
|
while connections.next().await.is_some() {}
|
||||||
let _ = connections.next().await;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue