programatik29 / axum-server

High level server designed to be used with axum framework.
MIT License
166 stars 54 forks source link

Refuse new connections during graceful shutdown #111

Closed Aeledfyr closed 4 months ago

Aeledfyr commented 4 months ago

Unlike std::net::TcpListener, tokio::net::TcpListener will internally accept TCP connections even when the application has stopped calling accept on the TcpListener. As such, connection attempts during a graceful shutdown will be accepted by tokio, but will not be processed; once the shutdown completes, the connections will be closed.

This PR drops the TcpListener before waiting for the shutdown to complete, so that new connection attempts during a shutdown are immediately refused, rather than them being accepted and then hanging until the shutdown completes.

abs0luty commented 4 months ago

Thanks!