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

A test to trigger 'earliest > now' assertion #1491

Merged
merged 8 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 10 additions & 13 deletions neqo-transport/src/connection/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ impl IdleTimeout {
self.timeout = min(self.timeout, peer_timeout);
}

pub fn expiry(&self, now: Instant, pto: Duration) -> Instant {
let start = match self.state {
fn start(&self, now: Instant) -> Instant {
match self.state {
IdleTimeoutState::Init => now,
IdleTimeoutState::PacketReceived(t) | IdleTimeoutState::AckElicitingPacketSent(t) => t,
};
}
}

pub fn expiry(&self, now: Instant, pto: Duration) -> Instant {
let delay = max(self.timeout, pto * 3);
qtrace!(
"IdleTimeout::expiry@{now:?} pto={pto:?} => {t:?}",
t = start + delay
);
start + delay
let t = self.start(now) + delay;
qtrace!("IdleTimeout::expiry@{now:?} pto={pto:?} => {t:?}");
t
}

pub fn on_packet_sent(&mut self, now: Instant) {
Expand Down Expand Up @@ -90,13 +91,9 @@ impl IdleTimeout {
}

fn keep_alive_timeout(&self, now: Instant, pto: Duration) -> Instant {
let start = match self.state {
IdleTimeoutState::Init => now,
IdleTimeoutState::PacketReceived(t) | IdleTimeoutState::AckElicitingPacketSent(t) => t,
};
// For a keep-alive timer, wait for half the timeout interval, but be sure
// not to wait too little or we will send many unnecessary probes.
start + max(self.timeout / 2, pto)
self.start(now) + max(self.timeout / 2, pto)
}

pub fn send_keep_alive(
Expand Down
43 changes: 17 additions & 26 deletions neqo-transport/src/connection/tests/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,8 @@ fn keep_alive_initiator() {
let stream = create_stream_idle(&mut server, &mut client);
let mut now = now();

// Marking the stream for keep-alive changes the idle timeout.
server.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut server, now, default_timeout() / 2);
assert_idle(&mut server, now, default_timeout());

// Wait that long and the server should send a PING frame.
now += default_timeout() / 2;
Expand All @@ -431,8 +430,8 @@ fn keep_alive_initiator() {
let out = server.process(out.as_ref(), now).dgram();
assert!(client.process(out.as_ref(), now).dgram().is_none());

// Check that there will be next keep-alive ping after default_timeout() / 2.
assert_idle(&mut server, now, default_timeout() / 2);
// Check that there will be next keep-alive ping after default_timeout().
assert_idle(&mut server, now, default_timeout());
now += default_timeout() / 2;
let pings_before2 = server.stats().frame_tx.ping;
let ping = server.process_output(now).dgram();
Expand All @@ -449,9 +448,8 @@ fn keep_alive_lost() {
let stream = create_stream_idle(&mut server, &mut client);
let mut now = now();

// Marking the stream for keep-alive changes the idle timeout.
server.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut server, now, default_timeout() / 2);
assert_idle(&mut server, now, default_timeout());

// Wait that long and the server should send a PING frame.
now += default_timeout() / 2;
Expand Down Expand Up @@ -480,7 +478,7 @@ fn keep_alive_lost() {
// return some small timeout for the recovry although it does not have
// any outstanding data. Therefore we call it after AT_LEAST_PTO.
now += AT_LEAST_PTO;
assert_idle(&mut server, now, default_timeout() / 2 - AT_LEAST_PTO);
assert_idle(&mut server, now, default_timeout() - AT_LEAST_PTO);
}

/// The other peer can also keep it alive.
Expand All @@ -492,9 +490,8 @@ fn keep_alive_responder() {
let stream = create_stream_idle(&mut server, &mut client);
let mut now = now();

// Marking the stream for keep-alive changes the idle timeout.
client.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut client, now, default_timeout() / 2);
assert_idle(&mut client, now, default_timeout());

// Wait that long and the client should send a PING frame.
now += default_timeout() / 2;
Expand All @@ -513,7 +510,7 @@ fn keep_alive_unmark() {
let stream = create_stream_idle(&mut client, &mut server);

client.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

client.stream_keep_alive(stream, false).unwrap();
assert_idle(&mut client, now(), default_timeout());
Expand Down Expand Up @@ -543,11 +540,11 @@ fn keep_alive_close() {
let stream = create_stream_idle(&mut client, &mut server);

client.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

client.stream_close_send(stream).unwrap();
transfer_force_idle(&mut client, &mut server);
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

server.stream_close_send(stream).unwrap();
transfer_force_idle(&mut server, &mut client);
Expand All @@ -564,17 +561,18 @@ fn keep_alive_reset() {
let stream = create_stream_idle(&mut client, &mut server);

client.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

client.stream_close_send(stream).unwrap();
transfer_force_idle(&mut client, &mut server);
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

server.stream_reset_send(stream, 0).unwrap();
transfer_force_idle(&mut server, &mut client);
assert_idle(&mut client, now(), default_timeout());

// The client will fade away from here.
eprintln!("The client will fade away from here.");
let t = now() + (default_timeout() / 2);
assert_eq!(client.process_output(t).callback(), default_timeout() / 2);
let t = now() + default_timeout();
Expand All @@ -590,7 +588,7 @@ fn keep_alive_stop_sending() {
let stream = create_stream_idle(&mut client, &mut server);

client.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

client.stream_close_send(stream).unwrap();
client.stream_stop_sending(stream, 0).unwrap();
Expand All @@ -614,14 +612,14 @@ fn keep_alive_multiple_stop() {
let stream = create_stream_idle(&mut client, &mut server);

client.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

let other = client.stream_create(StreamType::BiDi).unwrap();
client.stream_keep_alive(other, true).unwrap();
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

client.stream_keep_alive(stream, false).unwrap();
assert_idle(&mut client, now(), default_timeout() / 2);
assert_idle(&mut client, now(), default_timeout());

client.stream_keep_alive(other, false).unwrap();
assert_idle(&mut client, now(), default_timeout());
Expand Down Expand Up @@ -692,9 +690,8 @@ fn keep_alive_with_ack_eliciting_packet_lost() {

// Create a stream.
let stream = client.stream_create(StreamType::BiDi).unwrap();
// Marking the stream for keep-alive changes the idle timeout.
client.stream_keep_alive(stream, true).unwrap();
assert_idle(&mut client, now, IDLE_TIMEOUT / 2);
assert_idle(&mut client, now, IDLE_TIMEOUT);

// Send data on the stream that will be lost.
_ = client.stream_send(stream, DEFAULT_STREAM_DATA).unwrap();
Expand All @@ -709,12 +706,6 @@ fn keep_alive_with_ack_eliciting_packet_lost() {
let retransmit = client.process_output(now).dgram();
assert!(retransmit.is_some());

// The next callback should be for an idle PING.
assert_eq!(
client.process_output(now).callback(),
IDLE_TIMEOUT / 2 - pto
);

// Wait that long and the client should send a PING frame.
now += IDLE_TIMEOUT / 2 - pto;
let pings_before = client.stats().frame_tx.ping;
Expand Down
Loading