Fix client Initial key discard to trigger on any Handshake packet send#5899
Draft
Fix client Initial key discard to trigger on any Handshake packet send#5899
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #5664, #5899
Fix a circular dependency in client Initial key discard that causes RandomLoss handshake test failures.
Root cause: Per RFC 9001 §4.9.1, a client MUST discard Initial keys and clear the congestion control and recovery states when it first sends a Handshake packet. MsQuic only discarded Initial keys inside
QuicCryptoWriteFrames— which only runs when writing CRYPTO frames to a HANDSHAKE packet, not for every HANDSHAKE packet.If the INITIAL data is big and there is packet loss on the network, it is possible for that the number of INITIAL bytes in flight from the client perspective is higher than the congestion window.
When the client receives the server's Handshake flight and TLS produces the Finished message, the send path tries to flush it as a HANDSHAKE CRYPTO frame. However, CRYPTO frames are subject to congestion control (per RFC 9002 §3 — only ACK and CONNECTION_CLOSE bypass CC).
This result in a HANDSHAKE packet containing only an ACK frame (which bypasses CC) — but no CRYPTO frame carrying the Finished.
This creates a deadlock:
Eventually, the connection times out.
Fix: Move the client Initial key discard from
QuicCryptoWriteFrames(crypto.c) toQuicPacketBuilderFinalize(packet_builder.c), so it triggers on ANY Handshake packet send (including ACK-only). This breaks the circular dependency: the ACK-only HANDSHAKE packet triggers the discard → Initial BytesInFlight released → CC unblocks → queued flush sends the Finished.Testing
Existing tests cover this change — all 353 Handshake tests pass (including all RandomLoss and HandshakeSpecificLossPatterns variants), plus 1,328 Basic/Misc/Api tests.
Documentation
No documentation impact.