Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ping timeouts handling #33

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
}

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 @@

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 @@
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()));
}
}
Loading