#2687·quiche

0-RTT rejection keeps recovery state

Author: LiD0209Created Aug 31, 2026Updated Sep 20, 2026

0-RTT rejection keeps recovery state

Problem Description

RFC 9002 Section 6.4 requires discarding recovery state for all in-flight 0-RTT packets when 0-RTT is rejected. quiche detects TLS early-data rejection, but the client-side recovery state for the sent 0-RTT packet remains in the Application packet number space.

Standard Requirement

RFC 9002 Section 6.4, Discarding Keys and Packet State:

When 0-RTT is rejected, recovery state for all in-flight 0-RTT
packets is discarded.

The same section also says packets whose keys are discarded must be removed from bytes in flight.

Relevant Source Code

implementions/quiche/quiche/src/tls/mod.rs:644-647

rust
// SSL_ERROR_EARLY_DATA_REJECTED
15 => {
    self.reset_early_data_reject();
    Err(Error::Done)
},

TLS reports early-data rejection, resets BoringSSL's rejection state, and returns Done; no QUIC recovery cleanup is triggered here.

implementions/quiche/quiche/src/lib.rs:8847-8858

rust
fn drop_epoch_state(&mut self, epoch: packet::Epoch, now: Instant) {
    let crypto_ctx = &mut self.crypto_ctx[epoch];
    if crypto_ctx.crypto_open.is_none() {
        return;
    }
    crypto_ctx.clear();
    self.pkt_num_spaces[epoch].clear();

    let handshake_status = self.handshake_status();
    for (_, p) in self.paths.iter_mut() {
        p.recovery
            .on_pkt_num_space_discarded(epoch, handshake_status, now);

quiche has a generic path that can drop packet-number-space state and call recovery cleanup, but the early-data rejection path does not call it for 0-RTT/Application state.

implementions/quiche/quiche/src/recovery/congestion/recovery.rs:843-866

rust
fn on_pkt_num_space_discarded(
    &mut self, epoch: Epoch, handshake_status: HandshakeStatus, now: Instant,
) {
    let epoch = &mut self.epochs[epoch];

    let unacked_bytes = epoch
        .sent_packets
        .iter()
        .filter(|p| {
            p.in_flight && p.time_acked.is_none() && p.time_lost.is_none()
        })
        .fold(0, |acc, p| acc + p.size);

    self.bytes_in_flight.saturating_subtract(unacked_bytes, now);

    epoch.sent_packets.clear();
    epoch.clear_lost_frames();
    epoch.acked_frames.clear();

Legacy recovery would remove sent packet state and subtract in-flight bytes if invoked.

implementions/quiche/quiche/src/recovery/gcongestion/recovery.rs:1008-1015

rust
fn on_pkt_num_space_discarded(
    &mut self, epoch: packet::Epoch, handshake_status: HandshakeStatus,
    now: Instant,
) {
    let epoch = &mut self.epochs[epoch];
    self.bytes_in_flight
        .saturating_subtract(epoch.discard(&mut self.pacer), now);

gcongestion has equivalent cleanup for discarded packet-number-space state.

Runtime Evidence

Temporary test added to implementions/quiche/quiche/src/tests.rs and removed after execution. It creates a resumable session with 0-RTT enabled, then starts a new connection where the client sends 0-RTT but the server configuration rejects early data. After the client processes the server flight and leaves early-data state, the test expects Application recovery state to be empty.

rust
assert!(pipe.client.is_in_early_data());
assert_eq!(pipe.client.stream_send(4, b"hello", true), Ok(5));
let (len, _) = pipe.client.send(&mut buf).unwrap();
let _zrtt = buf[..len].to_vec();

let recovery = &pipe.client.paths.get_active().unwrap().recovery;
assert!(recovery.sent_packets_len(packet::Epoch::Application) > 0);
assert!(recovery.bytes_in_flight() > 0);

assert_eq!(pipe.server_recv(&mut initial), Ok(initial.len()));
let flight = test_utils::emit_flight(&mut pipe.server).unwrap();
test_utils::process_flight(&mut pipe.client, flight).unwrap();
assert!(!pipe.client.is_in_early_data());

let recovery = &pipe.client.paths.get_active().unwrap().recovery;
assert_eq!(
    (
        recovery.sent_packets_len(packet::Epoch::Application),
        recovery.bytes_in_flight()
    ),
    (0, 0)
);

Command:

cd implementions/quiche/quiche
cargo test --release zero_rtt_rejection_discards_recovery_state -- --nocapture

Result:

running 2 tests
cc_algorithm_name_1___cubic__ ... FAILED
cc_algorithm_name_2___bbr2_gcongestion__ ... FAILED

assertion `left == right` failed
left: (1, 68)
right: (0, 0)

assertion `left == right` failed
left: (1, 68)
right: (0, 0)

Both recovery backends retain one Application-space sent packet and 68 bytes in flight after 0-RTT is rejected.

Inconsistency Reason

The standard requires in-flight 0-RTT recovery state to be discarded and removed from bytes in flight. quiche exits early-data state after rejection, but recovery still reports (sent_packets_len, bytes_in_flight) = (1, 68) for the Application packet number space.

Impact

Rejected 0-RTT data can remain visible to loss recovery and congestion accounting. That can keep stale bytes in flight and allow later PTO/loss processing to reason about packets whose 0-RTT keys/data should already have been discarded.

Fix Direction

When TLS reports 0-RTT rejection to the client, discard recovery state for in-flight 0-RTT packets and subtract their bytes from bytes in flight. Because quiche stores 0-RTT in the Application packet number space, the fix should avoid discarding valid 1-RTT state if any can coexist in that space.