pub struct ServeWithGracefulShutdown<L, M, S, F, B> { /* private fields */ }Expand description
A server future with graceful shutdown enabled.
This type is created by calling Serve::with_graceful_shutdown. It implements
IntoFuture, so you can directly .await it.
When the shutdown signal completes, the server will:
- Stop accepting new connections
- Wait for all in-flight requests to complete (or until timeout if configured)
- Return once all connections are closed
Configure the shutdown timeout with with_shutdown_timeout.
Created by Serve::with_graceful_shutdown.
Implementations§
Source§impl<L: Listener, M, S, F, B> ServeWithGracefulShutdown<L, M, S, F, B>
impl<L: Listener, M, S, F, B> ServeWithGracefulShutdown<L, M, S, F, B>
Sourcepub fn with_shutdown_timeout(self, timeout: Duration) -> Self
pub fn with_shutdown_timeout(self, timeout: Duration) -> Self
Set a timeout for graceful shutdown.
If the timeout expires before all connections complete, a warning is logged and the server returns successfully. Note that this does not forcibly terminate connections - it only stops waiting for them.
§Example
use std::time::Duration;
serve(listener, app.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.with_shutdown_timeout(Duration::from_secs(30))
.await?; // Returns Ok(()) even if timeout expiresSourcepub fn max_connections(self, max: usize) -> Self
pub fn max_connections(self, max: usize) -> Self
Set the maximum number of concurrently accepted connections.
The default limit is 16,384. Once the limit is reached, serve stops
accepting connections until an existing connection closes.
Passing 0 disables the limit, equivalent to
disable_connection_limit. Values
above [tokio::sync::Semaphore::MAX_PERMITS] are clamped to that value.
Sourcepub fn disable_connection_limit(self) -> Self
pub fn disable_connection_limit(self) -> Self
Disable the default accepted-connection limit.
Sourcepub fn header_read_timeout(self, timeout: Option<Duration>) -> Self
pub fn header_read_timeout(self, timeout: Option<Duration>) -> Self
Set the timeout for receiving a complete request head.
The default is one minute. Pass None or Some(Duration::ZERO) to disable it.
See Serve::header_read_timeout for details.
Sourcepub fn local_addr(&self) -> Result<L::Addr>
pub fn local_addr(&self) -> Result<L::Addr>
Returns the local address this server is bound to.
Trait Implementations§
Source§impl<L, M, S, F, B> Debug for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Debug for ServeWithGracefulShutdown<L, M, S, F, B>
Source§impl<L, M, S, F, B> IntoFuture for ServeWithGracefulShutdown<L, M, S, F, B>where
L: Listener,
L::Addr: Debug,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
S: Service<Request<Incoming>, Response = Response<B>, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
M: for<'a> Service<IncomingStream<'a, L>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <M as Service<IncomingStream<'a, L>>>::Future: Send,
F: Future<Output = ()> + Send + 'static,
impl<L, M, S, F, B> IntoFuture for ServeWithGracefulShutdown<L, M, S, F, B>where
L: Listener,
L::Addr: Debug,
B: HttpBody + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn StdError + Send + Sync>>,
S: Service<Request<Incoming>, Response = Response<B>, Error = Infallible> + Clone + Send + 'static,
S::Future: Send,
M: for<'a> Service<IncomingStream<'a, L>, Error = Infallible, Response = S> + Send + 'static,
for<'a> <M as Service<IncomingStream<'a, L>>>::Future: Send,
F: Future<Output = ()> + Send + 'static,
Source§type IntoFuture = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
type IntoFuture = Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
Source§fn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Auto Trait Implementations§
impl<L, M, S, F, B> Freeze for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> !RefUnwindSafe for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Send for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Sync for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> Unpin for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> UnsafeUnpin for ServeWithGracefulShutdown<L, M, S, F, B>
impl<L, M, S, F, B> !UnwindSafe for ServeWithGracefulShutdown<L, M, S, F, B>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more