Skip to content

Commit

Permalink
Fix KeepAlive timeout handling in default dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed May 1, 2024
1 parent c9c85f2 commit c96b729
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
6 changes: 6 additions & 0 deletions ntex-io/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changes

## [1.1.0] - 2024-05-01

* Add IoRef::notify_timeout() helper method

* Fix KeepAlive timeout handling in default dispatcher

## [1.0.2] - 2024-03-31

* Add IoRef::is_wr_backpressure() method
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 = "1.0.2"
version = "1.1.0"
authors = ["ntex contributors <team@ntex.rs>"]
description = "Utilities for encoding and decoding frames"
keywords = ["network", "framework", "async", "futures"]
Expand Down
18 changes: 11 additions & 7 deletions ntex-io/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,19 @@ where
self.shared.io.tag()
);
}
return Err(DispatchItem::ReadTimeout);
Err(DispatchItem::ReadTimeout)
} else {
Ok(())
}
} else if self.flags.contains(Flags::KA_TIMEOUT) {
log::trace!(
"{}: Keep-alive error, stopping dispatcher",
self.shared.io.tag()
);
Err(DispatchItem::KeepAliveTimeout)
} else {
Ok(())
}

log::trace!(
"{}: Keep-alive error, stopping dispatcher",
self.shared.io.tag()
);
Err(DispatchItem::KeepAliveTimeout)
}
}

Expand Down
3 changes: 1 addition & 2 deletions ntex-io/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ impl IoState {
}

pub(super) fn notify_timeout(&self) {
log::trace!("{}: Timeout, notify dispatcher", self.tag.get());

let mut flags = self.flags.get();
if !flags.contains(Flags::DSP_TIMEOUT) {
flags.insert(Flags::DSP_TIMEOUT);
self.flags.set(flags);
self.dispatch_task.wake();
log::trace!("{}: Timer, notify dispatcher", self.tag.get());
}
}

Expand Down
6 changes: 6 additions & 0 deletions ntex-io/src/ioref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ impl IoRef {
self.0.timeout.get()
}

#[inline]
/// wakeup dispatcher and send keep-alive error
pub fn notify_timeout(&self) {
self.0.notify_timeout()
}

#[inline]
/// Start timer
pub fn start_timer(&self, timeout: Seconds) -> timer::TimerHandle {
Expand Down
2 changes: 1 addition & 1 deletion ntex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ntex-bytes = "0.1.25"
ntex-server = "1.0.5"
ntex-h2 = "0.5.4"
ntex-rt = "0.4.12"
ntex-io = "1.0.1"
ntex-io = "1.1.0"
ntex-net = "1.0.1"
ntex-tls = "1.1.0"

Expand Down
18 changes: 5 additions & 13 deletions ntex/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,16 @@ use ntex::http::client::{error::SendRequestError, Client};

#[ntex::main]
async fn main() -> Result<(), SendRequestError> {
std::env::set_var("RUST_LOG", "ntex=trace");
std::env::set_var("RUST_LOG", "trace");
env_logger::init();

let client = Client::new();

// Create request builder, configure request and send
let mut response = client
.get("https://www.rust-lang.org/")
.header("User-Agent", "ntex")
.send()
.await?;

// server http response
println!("Response: {:?}", response);

// read response body
let body = response.body().await.unwrap();
println!("Downloaded: {:?} bytes", body.len());
loop {
let _response = client.get("https://www.google.com").send().await.unwrap();
ntex::time::sleep(std::time::Duration::from_secs(10)).await;
}

Ok(())

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / coverage

unreachable expression

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / 1.75.0 - x86_64-unknown-linux-gnu

unreachable expression

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu

unreachable expression

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / nightly - x86_64-unknown-linux-gnu

unreachable expression

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / coverage

unreachable expression

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / 1.75.0 - x86_64-unknown-linux-gnu

unreachable expression

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / stable - x86_64-unknown-linux-gnu

unreachable expression

Check failure on line 16 in ntex/examples/client.rs

View workflow job for this annotation

GitHub Actions / nightly - x86_64-unknown-linux-gnu

unreachable expression
}

0 comments on commit c96b729

Please sign in to comment.