1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-05-18 23:15:19 +02:00

feat: add HttpServer::shutdown_signal (#3644)

This commit is contained in:
Rob Ede 2025-05-10 00:16:21 +01:00 committed by GitHub
parent f1b7cfb253
commit 6e902d1d5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 44 additions and 4 deletions

View File

@ -1,6 +1,8 @@
version: "0.2"
words:
- actix
- addrs
- httparse
- msrv
- rustup
- zstd

5
Cargo.lock generated
View File

@ -251,9 +251,9 @@ dependencies = [
[[package]]
name = "actix-server"
version = "2.5.1"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6398974fd4284f4768af07965701efbbb5fdc0616bff20cade1bb14b77675e24"
checksum = "a65064ea4a457eaf07f2fba30b4c695bf43b721790e9530d26cb6f9019ff7502"
dependencies = [
"actix-rt",
"actix-service",
@ -397,6 +397,7 @@ dependencies = [
"static_assertions",
"time",
"tokio",
"tokio-util",
"tracing",
"url",
"zstd",

View File

@ -2,6 +2,8 @@
## Unreleased
- Add `HttpServer::shutdown_signal()` method.
- Mark `HttpServer` as `#[must_use]`.
- Update `brotli` dependency to `8`.
## 4.10.2

View File

@ -132,7 +132,7 @@ compat-routing-macros-force-pub = ["actix-web-codegen?/compat-routing-macros-for
actix-codec = "0.5"
actix-macros = { version = "0.2.3", optional = true }
actix-rt = { version = "2.6", default-features = false }
actix-server = "2"
actix-server = "2.6"
actix-service = "2"
actix-utils = "3"
actix-tls = { version = "3.4", default-features = false, optional = true }
@ -188,6 +188,7 @@ static_assertions = "1"
tls-openssl = { package = "openssl", version = "0.10.55" }
tls-rustls = { package = "rustls", version = "0.23" }
tokio = { version = "1.24.2", features = ["rt-multi-thread", "macros"] }
tokio-util = "0.7"
zstd = "0.13"
[lints]

View File

@ -1,6 +1,8 @@
use std::{
any::Any,
cmp, fmt, io,
cmp, fmt,
future::Future,
io,
marker::PhantomData,
net,
sync::{Arc, Mutex},
@ -64,6 +66,7 @@ struct Config {
/// .await
/// }
/// ```
#[must_use]
pub struct HttpServer<F, I, S, B>
where
F: Fn() -> I + Send + Clone + 'static,
@ -312,6 +315,37 @@ where
self
}
/// Specify shutdown signal from a future.
///
/// Using this method will prevent OS signal handlers being set up.
///
/// Typically, a `CancellationToken` will be used, but any future _can_ be.
///
/// # Examples
///
/// ```no_run
/// use actix_web::{App, HttpServer};
/// use tokio_util::sync::CancellationToken;
///
/// # #[actix_web::main]
/// # async fn main() -> std::io::Result<()> {
/// let stop_signal = CancellationToken::new();
///
/// HttpServer::new(move || App::new())
/// .shutdown_signal(stop_signal.cancelled_owned())
/// .bind(("127.0.0.1", 8080))?
/// .run()
/// .await
/// # }
/// ```
pub fn shutdown_signal<Fut>(mut self, shutdown_signal: Fut) -> Self
where
Fut: Future<Output = ()> + Send + 'static,
{
self.builder = self.builder.shutdown_signal(shutdown_signal);
self
}
/// Sets timeout for graceful worker shutdown of workers.
///
/// After receiving a stop signal, workers have this much time to finish serving requests.