Skip to content

Commit

Permalink
Do not rely on not_ready(), always check service readiness (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 authored Nov 5, 2024
1 parent 9bf6f31 commit 0a37645
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
4 changes: 4 additions & 0 deletions ntex-io/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ntex-io/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-io"
version = "2.8.1"
version = "2.8.2"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Utilities for encoding and decoding frames"
keywords = ["network", "framework", "async", "futures"]
Expand Down
18 changes: 1 addition & 17 deletions ntex-io/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use crate::{Decoded, DispatchItem, IoBoxed, IoStatusUpdate, RecvError};

type Response<U> = <U as Encoder>::Item;

const READY_COUNT: u8 = 32;

#[derive(Clone, Debug)]
/// Shared dispatcher configuration
pub struct DispatcherConfig(Rc<DispatcherConfigInner>);
Expand Down Expand Up @@ -148,7 +146,6 @@ where
shared: Rc<DispatcherShared<S, U>>,
response: Option<PipelineCall<S, DispatchItem<U>>>,
cfg: DispatcherConfig,
ready_count: u8,
read_remains: u32,
read_remains_prev: u32,
read_max_timeout: Seconds,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -475,21 +471,10 @@ where
}

fn poll_service(&mut self, cx: &mut Context<'_>) -> Poll<PollService<U>> {
// 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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions ntex-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ pub trait Service<Req> {
/// 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
}
Expand Down
22 changes: 11 additions & 11 deletions ntex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit 0a37645

Please sign in to comment.