Ignore RTT sample if adjusting ack_delay causes it less than min_rtt before handshake confirmation
@@ -9619,6 +9619,7 @@ int ngtcp2_conn_early_data_rejected(ngtcp2_conn *conn) {
void ngtcp2_conn_update_rtt(ngtcp2_conn *conn, ngtcp2_duration rtt,
ngtcp2_duration ack_delay) {
ngtcp2_conn_stat *cstat = &conn->cstat;
+ ngtcp2_duration min_rtt;
rtt = ngtcp2_max(rtt, NGTCP2_GRANULARITY);
@@ -9629,15 +9630,28 @@ void ngtcp2_conn_update_rtt(ngtcp2_conn *conn, ngtcp2_duration rtt,
cstat->smoothed_rtt = rtt;
cstat->rttvar = rtt / 2;
} else {
- cstat->min_rtt = ngtcp2_min(cstat->min_rtt, rtt);
+ min_rtt = ngtcp2_min(cstat->min_rtt, rtt);
if (conn->flags & NGTCP2_CONN_FLAG_HANDSHAKE_CONFIRMED) {
ack_delay =
ngtcp2_min(ack_delay, conn->remote.transport_params.max_ack_delay);
+ } else if (ack_delay > 0 && rtt < cstat->min_rtt + ack_delay) {
+ /* Ignore RTT sample if adjusting ack_delay causes the sample
+ less than min_rtt before handshake confirmation. */
+ ngtcp2_log_info(
+ &conn->log, NGTCP2_LOG_EVENT_RCV,
+ "ignore rtt sample because ack_delay is too large latest_rtt=%" PRIu64
+ " min_rtt=%" PRIu64 " ack_delay=%" PRIu64,
+ (uint64_t)(rtt / NGTCP2_MILLISECONDS),
+ (uint64_t)(cstat->min_rtt / NGTCP2_MILLISECONDS),
+ (uint64_t)(ack_delay / NGTCP2_MILLISECONDS));
+ return;
}
- if (rtt > cstat->min_rtt + ack_delay) {
+
+ if (rtt > min_rtt + ack_delay) {
rtt -= ack_delay;
}
+ cstat->min_rtt = min_rtt;
cstat->rttvar = (cstat->rttvar * 3 + (cstat->smoothed_rtt < rtt
? rtt - cstat->smoothed_rtt
: cstat->smoothed_rtt - rtt)) /
