Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serve_connection should handle panic? #843

Closed
tisonkun opened this issue Jul 9, 2024 · 0 comments · Fixed by #844
Closed

serve_connection should handle panic? #843

tisonkun opened this issue Jul 9, 2024 · 0 comments · Fixed by #844

Comments

@tisonkun
Copy link
Contributor

tisonkun commented Jul 9, 2024

poem/poem/src/server.rs

Lines 168 to 197 in c66d78a

tokio::spawn(async move {
let serve_connection = serve_connection(socket, local_addr, remote_addr, scheme, ep, server_graceful_shutdown_token.clone(), idle_timeout);
if timeout.is_some() {
tokio::select! {
_ = serve_connection => {}
_ = timeout_token.cancelled() => {}
}
} else {
serve_connection.await;
}
if alive_connections.fetch_sub(1, Ordering::Acquire) == 1 {
// notify only if shutdown is initiated, to prevent notification when server is active.
// It's a valid state to have 0 alive connections when server is not shutting down.
if server_graceful_shutdown_token.is_cancelled() {
notify.notify_one();
}
}
});
}
}
}
}
drop(acceptor);
if alive_connections.load(Ordering::Acquire) > 0 {
tracing::info!(name = name, "wait for all connections to close.");
notify.notified().await;
}

We have a situation that serve_connection.await panic and thus alive_connections.fetch_sub doesn't execute, so that outer notify.notified().await blocks forever.

We should either handle panic, or do a timeout for waiting connections to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant