Skip to content

Commit

Permalink
Fix ping timeouts handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed May 1, 2024
1 parent e93e488 commit 32ecfd8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [0.5.5] - 2024-05-01

* Fix ping timeouts handling

## [0.5.4] - 2024-04-23

* Fix Config::frame_read_rate() method
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-h2"
version = "0.5.4"
version = "0.5.5"
license = "MIT OR Apache-2.0"
authors = ["Nikolay Kim <[email protected]>"]
description = "An HTTP/2 client and server"
Expand All @@ -21,7 +21,7 @@ unstable = []

[dependencies]
ntex-net = "1.0"
ntex-io = "1.0"
ntex-io = "1.1"
ntex-http = "0.1.11"
ntex-bytes = "0.1.24"
ntex-codec = "0.6.2"
Expand All @@ -30,7 +30,7 @@ ntex-util = "1.0.0"
ntex-rt = "0.4.11"

bitflags = "2"
fxhash = "0.2.1"
fxhash = "0.2"
log = "0.4"
pin-project-lite = "0.2"
thiserror = "1"
Expand All @@ -44,8 +44,8 @@ rand = "0.8.4"
# HPACK fixtures
hex = "0.4.3"
walkdir = "2.3.2"
serde = "1.0.0"
serde_json = "1.0.0"
serde = "1.0"
serde_json = "1.0"

ntex = { version = "1.2", features = ["openssl", "tokio"] }
ntex-tls = { version = "1.1", features = ["openssl"] }
Expand Down
11 changes: 9 additions & 2 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ bitflags::bitflags! {
const SECURE = 0b0001_0000;
const STREAM_REFUSED = 0b0010_0000;
const KA_TIMER = 0b0100_0000;
const RECV_PONG = 0b1000_0000;

Check warning on line 30 in src/connection.rs

View check run for this annotation

Codecov / codecov/patch

src/connection.rs#L30

Added line #L30 was not covered by tests
}
}

Expand Down Expand Up @@ -666,7 +667,7 @@ impl RecvHalfConnection {
}

pub(crate) fn recv_pong(&self, _: frame::Ping) {
self.0.io.stop_timer();
self.set_flags(ConnectionFlags::RECV_PONG);
}

pub(crate) fn recv_go_away(
Expand Down Expand Up @@ -808,6 +809,8 @@ async fn ping(st: Connection, timeout: time::Seconds, io: IoRef) {

let mut counter: u64 = 0;
let keepalive: time::Millis = time::Millis::from(timeout) + time::Millis(100);

st.set_flags(ConnectionFlags::RECV_PONG);
loop {
if st.is_closed() {
log::debug!("http client connection is closed, stopping keep-alive task");
Expand All @@ -817,9 +820,13 @@ async fn ping(st: Connection, timeout: time::Seconds, io: IoRef) {
if st.is_closed() {
break;
}
if !st.0.flags.get().contains(ConnectionFlags::RECV_PONG) {
io.notify_timeout();
break;
}

Check warning on line 826 in src/connection.rs

View check run for this annotation

Codecov / codecov/patch

src/connection.rs#L823-L826

Added lines #L823 - L826 were not covered by tests

counter += 1;
io.start_timer(timeout);
st.unset_flags(ConnectionFlags::RECV_PONG);

Check warning on line 829 in src/connection.rs

View check run for this annotation

Codecov / codecov/patch

src/connection.rs#L829

Added line #L829 was not covered by tests
st.encode(frame::Ping::new(counter.to_be_bytes()));
}
}

0 comments on commit 32ecfd8

Please sign in to comment.