fix(stream): avoid RST before initial HEADERS on idle streams #875
+82
−5
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
If a request body errored before the opening
HEADERSwere flushed,h2clears the pending frames and sendRST_STREAMfirst. That leads to a reset on an idle stream, which HTTP/2 forbids, leading peers to reply withPROTOCOL_ERROR/GOAWAY.But, more importantly, that
PROTOCOL_ERRORresponse closes the TCP connection (as a connection error per RFC 7540 5.4.1), disrupting other in‑flight streams and potentially leading to a reconnect loop.Expectations
HEADERS/PRIORITYare valid on idle streams.https://datatracker.ietf.org/doc/html/rfc7540#section-5.1
RST_STREAMframes MUST NOT be sent for a stream in the ‘idle’ state…PROTOCOL_ERROR.”https://datatracker.ietf.org/doc/html/rfc7540#section-6.4
After fix
When the stream is still pending open,
h2now keeps the queuedHEADERSand enqueues theRST_STREAMafter them.This prevents idle-stream resets and keeps behavior within the spec. Already-open streams keep the previous reset behavior.