From 9fa8d7fc5abb98efc7f0e36f9a4a8c5fc87d92f2 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 11 Oct 2021 05:12:57 +0100 Subject: [PATCH 1/3] avoid dependency on older tokios --- .cargo/config.toml | 1 - actix-codec/Cargo.toml | 2 +- actix-rt/Cargo.toml | 7 +++---- actix-server/Cargo.toml | 8 ++++---- local-channel/Cargo.toml | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 0e5de486..03a995c7 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,5 +1,4 @@ [alias] -chk = "check --workspace --all-features --tests --examples --bins" lint = "clippy --workspace --all-features --tests --examples --bins -- -Dclippy::todo" ci-doctest = "test --workspace --all-features --doc --no-fail-fast -- --nocapture" diff --git a/actix-codec/Cargo.toml b/actix-codec/Cargo.toml index 815f1039..7bf1c941 100644 --- a/actix-codec/Cargo.toml +++ b/actix-codec/Cargo.toml @@ -20,5 +20,5 @@ futures-core = { version = "0.3.7", default-features = false } futures-sink = { version = "0.3.7", default-features = false } log = "0.4" pin-project-lite = "0.2" -tokio = "1" +tokio = "1.5.1" tokio-util = { version = "0.6", features = ["codec", "io"] } diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index b466bb76..4b649252 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -8,8 +8,7 @@ authors = [ description = "Tokio-based single-threaded async runtime for the Actix ecosystem" keywords = ["async", "futures", "io", "runtime"] homepage = "https://actix.rs" -repository = "https://github.com/actix/actix-net" -documentation = "https://docs.rs/actix-rt" +repository = "https://github.com/actix/actix-net.git" categories = ["network-programming", "asynchronous"] license = "MIT OR Apache-2.0" edition = "2018" @@ -27,11 +26,11 @@ io-uring = ["tokio-uring"] actix-macros = { version = "0.2.0", optional = true } futures-core = { version = "0.3", default-features = false } -tokio = { version = "1.3", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } +tokio = { version = "1.5.1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } [target.'cfg(target_os = "linux")'.dependencies] tokio-uring = { version = "0.1", optional = true } [dev-dependencies] -tokio = { version = "1.2", features = ["full"] } +tokio = { version = "1.5.1", features = ["full"] } hyper = { version = "0.14", default-features = false, features = ["server", "tcp", "http1"] } diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index 89e1d4e2..92d5a25b 100755 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -7,7 +7,7 @@ authors = [ ] description = "General purpose TCP server built for the Actix ecosystem" keywords = ["network", "framework", "async", "futures"] -repository = "https://github.com/actix/actix-net" +repository = "https://github.com/actix/actix-net.git" categories = ["network-programming", "asynchronous"] license = "MIT OR Apache-2.0" edition = "2018" @@ -29,13 +29,13 @@ futures-core = { version = "0.3.7", default-features = false, features = ["alloc log = "0.4" mio = { version = "0.7.6", features = ["os-poll", "net"] } num_cpus = "1.13" -tokio = { version = "1.2", features = ["sync"] } +tokio = { version = "1.5.1", features = ["sync"] } [dev-dependencies] actix-codec = "0.4.0-beta.1" actix-rt = "2.0.0" bytes = "1" -env_logger = "0.8" +env_logger = "0.9" futures-util = { version = "0.3.7", default-features = false, features = ["sink"] } -tokio = { version = "1", features = ["io-util"] } +tokio = { version = "1.5.1", features = ["io-util"] } diff --git a/local-channel/Cargo.toml b/local-channel/Cargo.toml index 0ffd3597..1c20b941 100644 --- a/local-channel/Cargo.toml +++ b/local-channel/Cargo.toml @@ -18,4 +18,4 @@ futures-util = { version = "0.3.7", default-features = false } local-waker = "0.1" [dev-dependencies] -tokio = { version = "1", features = ["rt", "macros"] } +tokio = { version = "1.5.1", features = ["rt", "macros"] } From ca435b25750601861777b6bf744b842a6dcb3218 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 11 Oct 2021 05:14:34 +0100 Subject: [PATCH 2/3] prepare actix-server release 2.0.0-beta.6 --- actix-server/CHANGES.md | 20 +++++++++++--------- actix-server/Cargo.toml | 2 +- actix-server/src/builder.rs | 10 +++++++--- actix-server/src/server.rs | 9 ++++++++- actix-server/src/signals.rs | 16 ++++++++++++---- actix-server/src/test_server.rs | 23 +++++++++++------------ actix-server/src/worker.rs | 20 ++++++++++++-------- actix-tls/Cargo.toml | 2 +- 8 files changed, 63 insertions(+), 39 deletions(-) diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md index 69f5b08c..6b080daf 100644 --- a/actix-server/CHANGES.md +++ b/actix-server/CHANGES.md @@ -1,13 +1,15 @@ # Changes ## Unreleased - 2021-xx-xx -* Remove `config` module. `ServiceConfig`, `ServiceRuntime` public types are removed due to this change. [#349] -* Remove `ServerBuilder::configure` [#349] + + +## 2.0.0-beta.6 - 2021-10-11 * Add `io-uring` feature for enabling async file I/O on linux. [#374] -* Server no long listens to SIGHUP signal. - It actually did not take any action when receiving SIGHUP, the only thing SIGHUP did was to stop - the Server from receiving any future signal, because the `Signals` future stops on the first - signal received [#389] +* Server no long listens to `SIGHUP` signal. Previously, the received was not used but did block + subsequent exit signals from working. [#389] +* Remove `config` module. `ServiceConfig`, `ServiceRuntime` public types are removed due to + this change. [#349] +* Remove `ServerBuilder::configure` [#349] [#374]: https://github.com/actix/actix-net/pull/374 [#349]: https://github.com/actix/actix-net/pull/349 @@ -15,9 +17,9 @@ ## 2.0.0-beta.5 - 2021-04-20 -* Server shutdown would notify all workers to exit regardless if shutdown is graceful. - This would make all worker shutdown immediately in force shutdown case. [#333] - +* Server shutdown notifies all workers to exit regardless if shutdown is graceful. This causes all + workers to shutdown immediately in force shutdown case. [#333] + [#333]: https://github.com/actix/actix-net/pull/333 diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index 92d5a25b..8fd3112b 100755 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-server" -version = "2.0.0-beta.5" +version = "2.0.0-beta.6" authors = [ "Nikolay Kim ", "fakeshadow <24548779@qq.com>", diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index 46a55ef4..871abb5b 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -312,23 +312,25 @@ impl ServerBuilder { // Handle `SIGINT`, `SIGTERM`, `SIGQUIT` signals and stop actix system match sig { Signal::Int => { - info!("SIGINT received, exiting"); + info!("SIGINT received, starting forced shutdown"); self.exit = true; self.handle_cmd(ServerCommand::Stop { graceful: false, completion: None, }) } + Signal::Term => { - info!("SIGTERM received, stopping"); + info!("SIGTERM received, starting graceful shutdown"); self.exit = true; self.handle_cmd(ServerCommand::Stop { graceful: true, completion: None, }) } + Signal::Quit => { - info!("SIGQUIT received, exiting"); + info!("SIGQUIT received, starting forced shutdown"); self.exit = true; self.handle_cmd(ServerCommand::Stop { graceful: false, @@ -359,12 +361,14 @@ impl ServerBuilder { rt::spawn(async move { if graceful { + // wait for all workers to shut down let _ = join_all(stop).await; } if let Some(tx) = completion { let _ = tx.send(()); } + for tx in notify { let _ = tx.send(()); } diff --git a/actix-server/src/server.rs b/actix-server/src/server.rs index 6b0d0aea..f0dfca0b 100644 --- a/actix-server/src/server.rs +++ b/actix-server/src/server.rs @@ -15,8 +15,8 @@ pub(crate) enum ServerCommand { Pause(oneshot::Sender<()>), Resume(oneshot::Sender<()>), Signal(Signal), - /// Whether to try and shut down gracefully Stop { + /// True if shut down should be graceful. graceful: bool, completion: Option>, }, @@ -24,6 +24,13 @@ pub(crate) enum ServerCommand { Notify(oneshot::Sender<()>), } +/// Server handle. +/// +/// # Shutdown Signals +/// On UNIX systems, `SIGQUIT` will start a graceful shutdown and `SIGTERM` or `SIGINT` will start a +/// forced shutdown. On Windows, a CTRL-C signal will start a forced shutdown. +/// +/// A graceful shutdown will wait for all workers to stop first. #[derive(Debug)] pub struct Server( UnboundedSender, diff --git a/actix-server/src/signals.rs b/actix-server/src/signals.rs index cdd96b9c..c9cdb45e 100644 --- a/actix-server/src/signals.rs +++ b/actix-server/src/signals.rs @@ -4,27 +4,33 @@ use std::task::{Context, Poll}; use crate::server::Server; -/// Different types of process signals +/// Types of process signals. #[allow(dead_code)] #[derive(PartialEq, Clone, Copy, Debug)] pub(crate) enum Signal { - /// SIGINT + /// `SIGINT` Int, - /// SIGTERM + + /// `SIGTERM` Term, - /// SIGQUIT + + /// `SIGQUIT` Quit, } +/// Process signal listener. pub(crate) struct Signals { srv: Server, + #[cfg(not(unix))] signals: futures_core::future::LocalBoxFuture<'static, std::io::Result<()>>, + #[cfg(unix)] signals: Vec<(Signal, actix_rt::signal::unix::Signal)>, } impl Signals { + /// Spawns a signal listening future that is able to send commands to the `Server`. pub(crate) fn start(srv: Server) { #[cfg(not(unix))] { @@ -33,6 +39,7 @@ impl Signals { signals: Box::pin(actix_rt::signal::ctrl_c()), }); } + #[cfg(unix)] { use actix_rt::signal::unix; @@ -76,6 +83,7 @@ impl Future for Signals { } Poll::Pending => Poll::Pending, } + #[cfg(unix)] { for (sig, fut) in self.signals.iter_mut() { diff --git a/actix-server/src/test_server.rs b/actix-server/src/test_server.rs index 0611cf4b..ad6ee8ee 100644 --- a/actix-server/src/test_server.rs +++ b/actix-server/src/test_server.rs @@ -5,13 +5,12 @@ use actix_rt::{net::TcpStream, System}; use crate::{Server, ServerBuilder, ServiceFactory}; -/// The `TestServer` type. +/// A testing server. /// -/// `TestServer` is very simple test server that simplify process of writing -/// integration tests for actix-net applications. +/// `TestServer` is very simple test server that simplify process of writing integration tests for +/// network applications. /// /// # Examples -/// /// ``` /// use actix_service::fn_service; /// use actix_server::TestServer; @@ -39,7 +38,7 @@ pub struct TestServerRuntime { } impl TestServer { - /// Start new server with server builder + /// Start new server with server builder. pub fn start(mut factory: F) -> TestServerRuntime where F: FnMut(ServerBuilder) -> ServerBuilder + Send + 'static, @@ -64,7 +63,7 @@ impl TestServer { } } - /// Start new test server with application factory + /// Start new test server with application factory. pub fn with>(factory: F) -> TestServerRuntime { let (tx, rx) = mpsc::channel(); @@ -99,7 +98,7 @@ impl TestServer { } } - /// Get first available unused local address + /// Get first available unused local address. pub fn unused_addr() -> net::SocketAddr { let addr: net::SocketAddr = "127.0.0.1:0".parse().unwrap(); let socket = mio::net::TcpSocket::new_v4().unwrap(); @@ -111,27 +110,27 @@ impl TestServer { } impl TestServerRuntime { - /// Test server host + /// Test server host. pub fn host(&self) -> &str { &self.host } - /// Test server port + /// Test server port. pub fn port(&self) -> u16 { self.port } - /// Get test server address + /// Get test server address. pub fn addr(&self) -> net::SocketAddr { self.addr } - /// Stop http server + /// Stop server. fn stop(&mut self) { self.system.stop(); } - /// Connect to server, return tokio TcpStream + /// Connect to server, returning a Tokio `TcpStream`. pub fn connect(&self) -> std::io::Result { TcpStream::from_std(net::TcpStream::connect(self.addr)?) } diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 21f98027..b99b2da2 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -429,13 +429,15 @@ struct Restart { fut: LocalBoxFuture<'static, Result<(usize, BoxedServerService), ()>>, } -// Shutdown keep states necessary for server shutdown: -// Sleep for interval check the shutdown progress. -// Instant for the start time of shutdown. -// Sender for send back the shutdown outcome(force/grace) to StopCommand caller. +/// State necessary for server shutdown. struct Shutdown { + // Interval for checking the shutdown progress. timer: Pin>, + + /// Start time of shutdown. start_from: Instant, + + /// Notify of the shutdown outcome (force/grace) to stop caller. tx: oneshot::Sender, } @@ -521,23 +523,25 @@ impl Future for ServerWorker { self.poll(cx) } WorkerState::Shutdown(ref mut shutdown) => { - // Wait for 1 second. + // wait for 1 second ready!(shutdown.timer.as_mut().poll(cx)); if this.counter.total() == 0 { - // Graceful shutdown. + // graceful shutdown if let WorkerState::Shutdown(shutdown) = mem::take(&mut this.state) { let _ = shutdown.tx.send(true); } + Poll::Ready(()) } else if shutdown.start_from.elapsed() >= this.shutdown_timeout { - // Timeout forceful shutdown. + // timeout forceful shutdown if let WorkerState::Shutdown(shutdown) = mem::take(&mut this.state) { let _ = shutdown.tx.send(false); } + Poll::Ready(()) } else { - // Reset timer and wait for 1 second. + // reset timer and wait for 1 second let time = Instant::now() + Duration::from_secs(1); shutdown.timer.as_mut().reset(time); shutdown.timer.as_mut().poll(cx) diff --git a/actix-tls/Cargo.toml b/actix-tls/Cargo.toml index 9fa260c7..00082278 100755 --- a/actix-tls/Cargo.toml +++ b/actix-tls/Cargo.toml @@ -64,7 +64,7 @@ tokio-native-tls = { version = "0.3", optional = true } [dev-dependencies] actix-rt = "2.2.0" -actix-server = "2.0.0-beta.5" +actix-server = "2.0.0-beta.6" bytes = "1" env_logger = "0.8" futures-util = { version = "0.3.7", default-features = false, features = ["sink"] } From 5c555a9408c9e6e34aa9319f747a85e2f06c4751 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 11 Oct 2021 22:55:23 +0100 Subject: [PATCH 3/3] prepare actix-rt release 2.3.0 --- actix-rt/CHANGES.md | 5 ++++- actix-rt/Cargo.toml | 2 +- actix-rt/README.md | 4 ++-- actix-server/CHANGES.md | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 373640d3..642cf27a 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -1,8 +1,11 @@ # Changes ## Unreleased - 2021-xx-xx -* Add `io-uring` feature for enabling async file I/O on linux. [#374] + + +## 2.3.0 - 2021-10-11 * The `spawn` method can now resolve with non-unit outputs. [#369] +* Add experimental (semver-exempt) `io-uring` feature for enabling async file I/O on linux. [#374] [#369]: https://github.com/actix/actix-net/pull/369 [#374]: https://github.com/actix/actix-net/pull/374 diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index 4b649252..942d54aa 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-rt" -version = "2.2.0" +version = "2.3.0" authors = [ "Nikolay Kim ", "Rob Ede ", diff --git a/actix-rt/README.md b/actix-rt/README.md index 4ad75f09..eb1d1b6f 100644 --- a/actix-rt/README.md +++ b/actix-rt/README.md @@ -3,11 +3,11 @@ > Tokio-based single-threaded async runtime for the Actix ecosystem. [![crates.io](https://img.shields.io/crates/v/actix-rt?label=latest)](https://crates.io/crates/actix-rt) -[![Documentation](https://docs.rs/actix-rt/badge.svg?version=2.2.0)](https://docs.rs/actix-rt/2.2.0) +[![Documentation](https://docs.rs/actix-rt/badge.svg?version=2.3.0)](https://docs.rs/actix-rt/2.3.0) [![Version](https://img.shields.io/badge/rustc-1.46+-ab6000.svg)](https://blog.rust-lang.org/2020/03/12/Rust-1.46.html) ![MIT or Apache 2.0 licensed](https://img.shields.io/crates/l/actix-rt.svg)
-[![dependency status](https://deps.rs/crate/actix-rt/2.2.0/status.svg)](https://deps.rs/crate/actix-rt/2.2.0) +[![dependency status](https://deps.rs/crate/actix-rt/2.3.0/status.svg)](https://deps.rs/crate/actix-rt/2.3.0) ![Download](https://img.shields.io/crates/d/actix-rt.svg) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/WghFtEH6Hb) diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md index 6b080daf..54096eca 100644 --- a/actix-server/CHANGES.md +++ b/actix-server/CHANGES.md @@ -4,7 +4,7 @@ ## 2.0.0-beta.6 - 2021-10-11 -* Add `io-uring` feature for enabling async file I/O on linux. [#374] +* Add experimental (semver-exempt) `io-uring` feature for enabling async file I/O on linux. [#374] * Server no long listens to `SIGHUP` signal. Previously, the received was not used but did block subsequent exit signals from working. [#389] * Remove `config` module. `ServiceConfig`, `ServiceRuntime` public types are removed due to