quiche icon indicating copy to clipboard operation
quiche copied to clipboard

quiche does not reset stream state after 0-RTT rejection

Open LiD0209 opened this issue 3 months ago • 1 comments

quiche does not reset stream state after 0-RTT rejection

Summary

After the client learns that 0-RTT was rejected, quiche leaves all stream state untouched: streams created during 0-RTT keep their send offsets, FIN state and identity. This violates an unconditional MUST in RFC 9001 Section 4.6.2. quic-go implements exactly this reset, confirming the expected behavior.

Standard

RFC 9001 Section 4.6.2, Accepting and Rejecting 0-RTT:

When 0-RTT is rejected, all connection characteristics that the client assumed might be incorrect. This includes the choice of application protocol, transport parameters, and any application configuration. The client therefore MUST reset the state of all streams, including application state bound to those streams.

The MUST has no "if it is able to detect" clause, and the client always knows the rejection (the TLS layer reports it), so it applies unconditionally. Related: RFC 9001 Section 4.6.2 also says a rejecting server MUST NOT process any 0-RTT packets, so the server holds no stream state for the 0-RTT writes.

Code

  • implementions/quiche/quiche/src/tls/mod.rs:645 — the only rejection handling: it resets a BoringSSL flag and returns; no transport-level stream rollback:
15 => { // SSL_ERROR_EARLY_DATA_REJECTED
    self.reset_early_data_reject();
    Err(Error::Done)
},
  • implementions/quiche/quiche/src/lib.rs — no other path consumes the rejection for stream state; every "reset stream" hit is RST_STREAM frame processing (a different concept). The client's send offsets, FIN flags and the stream map all survive the rejection.
  • Reference implementation, quic-go — on tls.QUICRejectedEarlyData it calls cryptoSetup.rejected0RTT() (internal/handshake/crypto_setup.go:441), which emits EventDiscard0RTTKeys; the connection then runs dropEncryptionLevel(Encryption0RTT) (connection.go:2303):
case protocol.Encryption0RTT:
    c.streamsMap.ResetFor0RTT()          // close streams with Err0RTTRejected, reset maps to initial state
    c.framer.Handle0RTTRejection()       // requeue 0-RTT stream data for retransmission
    return c.connFlowController.Reset()  // reset connection-level flow control

ResetFor0RTT (streams_map.go:343) makes subsequent OpenStream/AcceptStream return Err0RTTRejected until the application explicitly resumes. quiche has no equivalent.

Runtime evidence

The probe inserted stream_reset_probe.rs into quiche/src/tests.rs. The client resumes a session, writes 5 bytes + FIN on stream 4 in 0-RTT (the packet is withheld, so the server never sees it), the server declines early data, and the client processes the server's first flight (learns the rejection). Stream state is captured before and after:

$env:LINK='msvcrtd.lib'
cargo test -q -p quiche rejected_zero_rtt_stream_state_is_not_reset -- --nocapture

On the fresh 2026-08-26 run, the test observed:

rejected_0rtt reason=4 before=len:1,front:5,back:5 after=len:1,front:5,back:5
test result: ok. 1 passed; 0 failed

reason=4 = ssl_early_data_peer_declined. len is the number of live streams, front/back are the lowest buffered / highest written send offsets of stream 4: before and after the rejection the stream still exists and still believes it has sent offsets 0-4. A compliant reset would bring the send state back to 0.

Impact and fix

Impact: after rejection the client believes stream 4 carries 5 bytes + FIN, but the server holds no state for it at all. Any later write on the same stream ID goes out at the stale offset (>= 5), which the server interprets as data with an unfilled gap at 0-4; the stream can deadlock and the 0-RTT bytes are silently lost, contrary to the RFC's expectation that the client starts the streams fresh.

Fix: when the TLS layer reports SSL_ERROR_EARLY_DATA_REJECTED, reset transport stream state at the connection level: drop (or rewind to offset 0) all locally open streams' send state and any buffered send data, clear FIN-sent flags, and surface the rejection to the application (e.g. expose it like quic-go's Err0RTTRejected) so application state bound to those streams can be rebuilt. Keep a test asserting the stream state is reset after rejection, plus a positive control for the accepted case.

LiD0209 avatar Aug 31 '26 06:08 LiD0209

I am working on the transport/application side of 0-RTT rejection and have a local prototype with an end-to-end test: withhold the client's 0-RTT STREAM packet, have the server reject early data, then replay that request on the same stream ID in 1-RTT and verify it begins at offset zero.

Proposed shape:

  • Preserve the TLS SSL_ERROR_EARLY_DATA_REJECTED signal in Connection and expose a boolean for applications to detect the rejection.
  • Reset transport stream state and connection-level sent flow-control accounting, while keeping Application packet numbers monotonic.
  • Require applications holding an early h3::Connection to recreate it and replay requests; update the example client to demonstrate this.

This must be integrated with recovery cleanup in #2687. Clearing streams by itself is unsafe: rejected 0-RTT frames left in recovery could be retransmitted after the application has replayed them. Conversely, clearing recovery without an application signal can silently lose the request. I see that #2687 already has an implementation discussion, so I do not want to duplicate that work.

Would maintainers prefer a persistent Connection::early_data_rejected() status plus application-driven replay, or an explicit event/one-shot API? I can shape the transport and H3 follow-up around the recovery design.

namtran1812 avatar Sep 29 '26 18:09 namtran1812