Skip to content

Commit

Permalink
Propagate the keep_alive flag through IdleTimeout::expired
Browse files Browse the repository at this point in the history
  • Loading branch information
KershawChang committed Nov 15, 2023
1 parent 8a3aaa2 commit d207294
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions neqo-transport/src/connection/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl IdleTimeout {
}
}

pub fn expired(&self, now: Instant, pto: Duration) -> bool {
now >= self.expiry(now, pto, false)
pub fn expired(&self, now: Instant, pto: Duration, keep_alive: bool) -> bool {
now >= self.expiry(now, pto, keep_alive)
}

pub fn send_keep_alive(
Expand Down
3 changes: 2 additions & 1 deletion neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,8 @@ impl Connection {
}

let pto = self.pto();
if self.idle_timeout.expired(now, pto) {
let keep_alive = self.streams.need_keep_alive();
if self.idle_timeout.expired(now, pto, keep_alive) {
qinfo!([self], "idle timeout expired");
self.set_state(State::Closed(ConnectionError::Transport(
Error::IdleTimeout,
Expand Down
22 changes: 22 additions & 0 deletions neqo-transport/src/connection/tests/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,3 +743,25 @@ fn keep_alive_with_ack_eliciting_packet_lost() {
assert!(matches!(out, Output::None));
assert!(matches!(client.state(), State::Closed(_)));
}

#[test]
fn keep_alive_with_unresponsive_server() {
let mut client = default_client();
let mut server = default_server();
connect(&mut client, &mut server);

let mut now = now();
let client_stream = client.stream_create(StreamType::BiDi).unwrap();
client.stream_keep_alive(client_stream, true).unwrap();

for _ in 0..100 {
if client.stream_send(client_stream, &[0x0; 500]).is_err() {
break;
}
if let Output::Callback(t) = client.process_output(now) {
now += t;
}
}
// Connection should be closed due to idle timeout.
assert!(matches!(client.state(), State::Closed(_)));
}

0 comments on commit d207294

Please sign in to comment.