Skip to content

Commit

Permalink
Fix KeepAlive timeout handling in default dispatcher (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed May 1, 2024
1 parent 316f908 commit 33490cd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 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

0 comments on commit 33490cd

Please sign in to comment.