pub struct ServerHandle { /* private fields */ }Expand description
A handle to a server started by one of the Server::run* methods.
Dropping this handle without calling shutdown() leaves the server running in the
background for the life of the process. Call shutdown() to stop accepting new
connections and wait for already-accepted connections to finish before returning.
Implementations§
Source§impl ServerHandle
impl ServerHandle
Sourcepub async fn shutdown(self)
pub async fn shutdown(self)
Stop accepting new connections and wait up to DEFAULT_SHUTDOWN_DRAIN_TIMEOUT
(5s) for in-flight connections to finish on their own. Equivalent to
shutdown_with_timeout(DEFAULT_SHUTDOWN_DRAIN_TIMEOUT) — see that method for what
happens to connections still open once the grace period elapses.
Sourcepub async fn shutdown_with_timeout(self, drain_timeout: Duration)
pub async fn shutdown_with_timeout(self, drain_timeout: Duration)
Stop accepting new connections and wait up to drain_timeout for in-flight
connections to finish on their own.
Connections still open once drain_timeout elapses are aborted rather than
waited on further: dropping the accept task drops its JoinSet, which aborts
every task still tracked in it (see tokio::task::JoinSet’s own drop behavior) —
which in turn drops each connection’s socket, closing it. This is what bounds
shutdown when a connection has no natural end of its own (the live-reload SSE
stream is the motivating case: it stays open until a watched file changes, which
may never happen before the process needs to exit).