Repository navigation
Conversation
… with STREAM_CLOSED, and HEADERS without END_STREAM on a body-reader request with PROTOCOL_ERROR (#615) A request's stream is half-closed (remote) once its END_STREAM has arrived, and RFC 9113 5.1 makes any frame on it other than WINDOW_UPDATE, PRIORITY or RST_STREAM a stream error of STREAM_CLOSED; 6.1 says the same of DATA. A buffered request leaves _streams at its END_STREAM, and its answer's window waits in _responseWindows until the answer has ended. HandleData dropped DATA it found only there, and credited it back with a stream WINDOW_UPDATE when it did not end the stream; HandleHeaders decoded such a HEADERS and dropped it as a closed stream's. A body-reader request stays in _streams, and a HEADERS after its END_STREAM was decoded aside and dropped like trailers. So was a HEADERS without END_STREAM while its body still arrived, which 8.1 makes malformed, a stream error of PROTOCOL_ERROR, and which the buffered path already resets. Those frames now reset the stream as a window overrun does: the answer's window goes, the stream is reset, and a writer parked on its credit wakes. A buffered answer is not written, a streamed writer's next flush reports the peer gone, and a rest parked on credit stops and frees its writer. A header block is decoded whole first, across its CONTINUATION frames, so HPACK stays in step: a body-reader request's HEADERS marks the stream, and the block's END_HEADERS resets it. Frames on a stream whose answer has ended are still dropped, as a closed stream's. With a body reader, a buffered answer parked on credit leaves _streams while its request may still be arriving, so on such a connection DATA and HEADERS found only in _responseWindows keep their old handling. Http2StreamStateTests (Unit): DATA (ending the stream, not ending it, empty) and HEADERS (ending it, not ending it, split over CONTINUATION) after a buffered request's END_STREAM on its HEADERS, its last DATA or its trailers, in the same read and while its handler is parked, reset only that stream with STREAM_CLOSED, send nothing else on it, keep HPACK in step and leave the connection serving; the same for HEADERS after a body-reader request's END_STREAM, whose handler reads an empty end again, and for HEADERS without END_STREAM while its body arrives, with PROTOCOL_ERROR and a read that raises. A split block is reset only at its END_HEADERS. A streamed answer's next flush reports the stream gone, and an answer parked on credit, buffered or streamed, wakes and lets go without credit. Two controls: frames after the answer has ended draw no reset or credit, and with a body reader an upload behind a buffered answer parked on credit still ends with its trailers.
This was referenced Nov 14, 2026
Owner
Author
|
Closed: frames after a request's END_STREAM come only from a client already in error, and no real client sends them, so the extra reset paths aren't worth their code. |
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.
Fixes #615.
What was wrong
RFC 9113 5.1: once a request's END_STREAM has arrived its stream is half-closed (remote), and any frame on it other than WINDOW_UPDATE, PRIORITY or RST_STREAM is a stream error of STREAM_CLOSED; 6.1 says the same of DATA. RFC 9113 8.1: a HEADERS without END_STREAM after the block that opens a request makes the request malformed, a stream error of PROTOCOL_ERROR (8.1.1).
ioxide.http2 checked neither in these cases:
_streamsat its END_STREAM, and its answer's window waits in_responseWindowsuntil the answer has ended. DATA on it reached the not-found branch ofHandleData, which dropped it, and credited it back with a stream WINDOW_UPDATE when it did not end the stream. HEADERS on it was decoded and dropped as a closed stream's.BodyReaderbranch ofHandleHeaders, which decodes trailers aside and keeps only their END_STREAM, so it was dropped. So was a HEADERS without END_STREAM while the body was still arriving, which the buffered path already resets with PROTOCOL_ERROR.Reproduced at main over a real h2c connection: a scratch program served
Http2Connectionon a test server and wrote each case below to a raw socket in one write, so every frame lands in one read, followed by a GET on stream 3.Stream 3 was answered in every case. The new unit tests fail at main the same way.
What changes
src/protocols/ioxide.http2/Http2Connection.Frames.csonly.HandleData: DATA on a stream that is answering but no longer in_streamsresets it with STREAM_CLOSED. Without a body reader such a stream has always ended its request (see below for the body-reader case).DiscardHeaderBlock: once a block decoded aside is whole, CONTINUATION included, it resets its stream when the stream cannot take it: with STREAM_CLOSED when the stream is answering out of_streams, or, for a stream still in_streams, when its HEADERS marked it.HandleHeaders,BodyReaderbranch: a block after the request's END_STREAM, or one without END_STREAM, sets the request's existingMalformedflag before the block is decoded aside, and the block's END_HEADERS resets the stream: STREAM_CLOSED once the request has ended, PROTOCOL_ERROR while it is still arriving. Only trailers that end the request still end its body.ResetAnswering, the three steps the window-overrun and content-length resets take: the answer's window leaves_responseWindows,ResetStream, thenReleaseCreditWaiters.Each of these resets waits until its header block has been decoded whole, so HPACK stays in step and a block split over CONTINUATION is reset at its END_HEADERS. Nothing new is kept: the decision reads
_streams,_responseWindows, and the request'sRequestEndedandMalformed.With a body reader, main retires a request whose buffered answer is parked on credit while its upload may still be arriving:
RetireStreamtakes it out of_streamsand keeps its window. On such a connection a stream answering out of_streamsmay still be uploading, so both new checks there apply only without a body reader, and those streams keep main's handling: DATA is credited, HEADERS dropped. #604 keeps such a request in_streams, after which the gate can go (see Overlaps).What a caller sees
FlushAsyncreportsIsCompleted, as after the peer's own reset; an answer parked on credit stops and frees its writer without waiting for credit the client will not send. The connection serves on.IOException(body cut off) instead of more body, and its answer is not sent: RST_STREAM(PROTOCOL_ERROR).Tests
tests/Ioxide.Tests.Unit/Http2StreamStateTests.cs, 14 tests over the strict test pipe. Each sends stream 1's request, the late frames, then a GET on stream 3, and checks every frame the server wrote:Each part of the fix reverted on its own, with the Unit suite rebuilt and rerun (the first failing check of each test quoted):
Http2Connection.Frames.cs)DATA with END_STREAM came after a request's END_STREAM on its HEADERS, and the server wrote []; 9 and 10 passHandleDataDATA, without a body reader came after the request's END_STREAM, and the handler's next flush: flush not completed, 7DATA came after the request's END_STREAM, and its parked answer was left waiting on creditDiscardHeaderBlockbuffered, and the server wrote [], 6 (HEADERS, without a body reader), 7 (HEADERS)with a body reader, and the server wrote [], 4 (both), 6 (HEADERS, with a body reader), 8expected [read ended 'aaaaa', flush completed], got [never got past its flush]one HEADERS without END_STREAM came while the body arrived, and the server wrote []_responseWindows.RemoveinResetAnsweringstream 1 carried [RST_STREAM STREAM_CLOSED, HEADERS, DATA]ReleaseCreditWaitersinResetAnsweringleft waiting on credit, 8got [never got past its flush]HandleDatah2 early answer: an upload still arriving while a buffered answer is parked on credit is credited on its stream(expected [16384], got [0]), 10drew [1 STREAM_CLOSED]DiscardHeaderBlockan upload that ended with its trailers drew [1 STREAM_CLOSED]buffered, the stream was reset with [1 STREAM_CLOSED] before its block's CONTINUATION came(with a body reader, ...with only that path changed)Suites
Built pinned with
dotnet build -c Release ioxide.slnx, each suite run alone:Http, Tls, File, Pg and Redis were not run locally: none of them reaches
Http2Connection's frame handling, the only code changed. CI runs them all.Overlaps
git merge-tree --write-tree origin/fix-<n> HEADagainst every open fix branch: exit 0 for fix-581, fix-583 to fix-587 and fix-589 to fix-592; exit 1 for fix-588 only.http2: DATA after a request's END_STREAM resets its stream with STREAM_CLOSED instead of reading as more of its body (#589) #599 (fix-589), merges cleanly. It resets DATA after END_STREAM on a stream still in
_streams, where only a body-reader request stays past its END_STREAM; this PR covers DATA found only in_responseWindowsand every HEADERS case, so together they cover DATA and HEADERS after END_STREAM on both kinds of stream. Its three reset lines are whatResetAnsweringdoes, and could call it.http2: an answer waiting on the client's credit has its unread upload credited, so a client that uploads everything first gets it (#588) #604 (fix-588), one conflict, in
HandleData's not-found branch: http2: an answer waiting on the client's credit has its unread upload credited, so a client that uploads everything first gets it (#588) #604 replaces main's credit there withreturn;, since it keeps a request whose answer waits on credit in_streams. Resolve it by keeping this PR's reset without its body-reader gate, and dropping the credit as http2: an answer waiting on the client's credit has its unread upload credited, so a client that uploads everything first gets it (#588) #604 does:and, with no textual conflict, the same gate goes in
DiscardHeaderBlock:else if (_responseWindows.ContainsKey(streamId)). With http2: an answer waiting on the client's credit has its unread upload credited, so a client that uploads everything first gets it (#588) #604 a stream answering out of_streamshas ended its request with or without a body reader. A body-reader request kept open behind a parked answer is then handled in_streams: HEADERS by this PR'sBodyReaderbranch, DATA by http2: DATA after a request's END_STREAM resets its stream with STREAM_CLOSED instead of reading as more of its body (#589) #599.I built main with http2: DATA after a request's END_STREAM resets its stream with STREAM_CLOSED instead of reading as more of its body (#589) #599, http2: an answer waiting on the client's credit has its unread upload credited, so a client that uploads everything first gets it (#588) #604 and this branch merged in, with that resolution (a scratch tree, not pushed), and ran the suites there: Unit 289 passed, E2E 735 passed, Chaos 105 passed, none failed or skipped, http2: DATA after a request's END_STREAM resets its stream with STREAM_CLOSED instead of reading as more of its body (#589) #599's and http2: an answer waiting on the client's credit has its unread upload credited, so a client that uploads everything first gets it (#588) #604's new tests and this PR's among them.
Of the issues being fixed in parallel, #614 (the preface flush and the first read, in
Http2Connection.csandHttp2Connection.Write.cs) and #617 (Http2ResponseWriter.EnsureStaging) also touch ioxide.http2, in files this PR leaves alone. The branches already pushed for the others (fix-605 to fix-609, fix-611) merge-tree cleanly with this one.For the reviewer
_responseWindows. A streamed answer, and a buffered rest parked on credit, give it up only once the flush carrying their END_STREAM has completed, so a late frame landing during that flush is reset just behind the END_STREAM. A scratch test (not committed) holds the flush of a streamed answer that completes outside the read pass and sends DATA without END_STREAM meanwhile: this PR writesHEADERS, DATA END_STREAM, RST_STREAM STREAM_CLOSEDon the stream, mainHEADERS, DATA END_STREAM, WINDOW_UPDATE +5. http2: DATA after a request's END_STREAM resets its stream with STREAM_CLOSED instead of reading as more of its body (#589) #599 has the same window for DATA on a body-reader request.Malformedinstead would move that reset to the END_HEADERS as well. Left as it is.Malformedgains a second use: on a body-reader request already being served it marks a block that request cannot take, so that the block's END_HEADERS resets the stream. That is the only state that has to outlive a HEADERS split over CONTINUATION, and nothing else readsMalformedonce the request has been dispatched.