From 0a376457f1f6f37295cb8a9c32fa5ded2d636c71 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 5 Nov 2024 15:35:34 +0500 Subject: [PATCH] Do not rely on not_ready(), always check service readiness (#459) --- ntex-io/CHANGES.md | 4 ++++ ntex-io/Cargo.toml | 2 +- ntex-io/src/dispatcher.rs | 18 +----------------- ntex-service/src/lib.rs | 2 ++ ntex/Cargo.toml | 22 +++++++++++----------- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/ntex-io/CHANGES.md b/ntex-io/CHANGES.md index 6ad6b5ab..c4d0aa3c 100644 --- a/ntex-io/CHANGES.md +++ b/ntex-io/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [2.8.2] - 2024-11-05 + +* Do not rely on not_ready(), always check service readiness + ## [2.8.1] - 2024-11-04 * Periodically check readiness diff --git a/ntex-io/Cargo.toml b/ntex-io/Cargo.toml index 1d9c4cfe..f4a5b406 100644 --- a/ntex-io/Cargo.toml +++ b/ntex-io/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-io" -version = "2.8.1" +version = "2.8.2" authors = ["ntex contributors "] description = "Utilities for encoding and decoding frames" keywords = ["network", "framework", "async", "futures"] diff --git a/ntex-io/src/dispatcher.rs b/ntex-io/src/dispatcher.rs index 85db6cd4..4d2c467b 100644 --- a/ntex-io/src/dispatcher.rs +++ b/ntex-io/src/dispatcher.rs @@ -11,8 +11,6 @@ use crate::{Decoded, DispatchItem, IoBoxed, IoStatusUpdate, RecvError}; type Response = ::Item; -const READY_COUNT: u8 = 32; - #[derive(Clone, Debug)] /// Shared dispatcher configuration pub struct DispatcherConfig(Rc); @@ -148,7 +146,6 @@ where shared: Rc>, response: Option>>, cfg: DispatcherConfig, - ready_count: u8, read_remains: u32, read_remains_prev: u32, read_max_timeout: Seconds, @@ -235,7 +232,6 @@ where cfg: cfg.clone(), response: None, error: None, - ready_count: 0, read_remains: 0, read_remains_prev: 0, read_max_timeout: Seconds::ZERO, @@ -475,21 +471,10 @@ where } fn poll_service(&mut self, cx: &mut Context<'_>) -> Poll> { - // check service readiness - if self.flags.contains(Flags::READY) { - if self.ready_count != 0 && self.shared.service.poll_not_ready(cx).is_pending() - { - self.ready_count -= 1; - return Poll::Ready(self.check_error()); - } - self.flags.remove(Flags::READY); - } - // wait until service becomes ready match self.shared.service.poll_ready(cx) { Poll::Ready(Ok(_)) => { - self.ready_count = READY_COUNT; - self.flags.insert(Flags::READY); + let _ = self.shared.service.poll_not_ready(cx); Poll::Ready(self.check_error()) } // pause io read task @@ -738,7 +723,6 @@ mod tests { error: None, st: DispatcherState::Processing, response: None, - ready_count: 0, read_remains: 0, read_remains_prev: 0, read_max_timeout: Seconds::ZERO, diff --git a/ntex-service/src/lib.rs b/ntex-service/src/lib.rs index af95c084..67253013 100644 --- a/ntex-service/src/lib.rs +++ b/ntex-service/src/lib.rs @@ -124,6 +124,8 @@ pub trait Service { /// Unlike the "ready()" method, the "not_ready()" method returns /// only when the service becomes unready. This method is intended /// for actively monitoring and maintaining the service state. + /// + /// "not_ready()" implementation is optional. async fn not_ready(&self) { std::future::pending().await } diff --git a/ntex/Cargo.toml b/ntex/Cargo.toml index 7a9fc44b..a2490d51 100644 --- a/ntex/Cargo.toml +++ b/ntex/Cargo.toml @@ -61,15 +61,15 @@ ws = ["dep:sha-1"] brotli = ["dep:brotli2"] [dependencies] -ntex-codec = "0.6.2" +ntex-codec = "0.6" ntex-http = "0.1.12" -ntex-router = "0.5.3" +ntex-router = "0.5" ntex-service = "3.3" -ntex-macros = "0.1.3" +ntex-macros = "0.1" ntex-util = "2.5" ntex-bytes = "0.1.27" ntex-server = "2.5" -ntex-h2 = "1.2" +ntex-h2 = "1.4" ntex-rt = "0.4.19" ntex-io = "2.8" ntex-net = "2.4" @@ -80,24 +80,24 @@ bitflags = "2" bytes = "1" log = "0.4" pin-project-lite = "0.2" -regex = { version = "1.10", default-features = false, features = ["std"] } -serde = { version = "1.0", features = ["derive"] } +regex = { version = "1.11", default-features = false, features = ["std"] } +serde = { version = "1", features = ["derive"] } sha-1 = { version = "0.10", optional = true } -thiserror = "1.0" +thiserror = "1" nanorand = { version = "0.7", default-features = false, features = [ "std", "wyrand", ] } # http/web framework -httparse = "1.8" +httparse = "1.9" httpdate = "1.0" encoding_rs = "0.8" mime = "0.3" percent-encoding = "2.3" -serde_json = "1.0" +serde_json = "1" serde_urlencoded = "0.7" -url-pkg = { version = "2.4", package = "url", optional = true } +url-pkg = { version = "2.5", package = "url", optional = true } coo-kie = { version = "0.18", package = "cookie", optional = true } # openssl @@ -109,7 +109,7 @@ webpki-roots = { version = "0.26", optional = true } # compression brotli2 = { version = "0.3.2", optional = true } -flate2 = { version = "1.0.22", optional = true } +flate2 = { version = "1.0", optional = true } [dev-dependencies] env_logger = "0.11"