Repository navigation
Closed
Conversation
… credited, so a client that uploads everything first gets it (#588) RFC 9113 8.1 lets a server answer before its request has arrived. A client that reads its response only once its upload has ended, as .NET's HttpClient does with a content that is not duplex, credits the response only then. An answer past that client's stream window waited on the credit for its END_STREAM, while the server credited the request's stream only as its handler read: a handler that answered unread left the upload holding the server's stream window (InitialWindowSize, 256 KiB by default), and neither side could move. A streamed answer hung whether its handler awaited CompleteAsync, which waited for that credit, or left the completion to the stack, which waited the same way; a buffered one hung once the upload had filled its window before the handler returned, since the queued body was dropped uncredited. And a buffered answer parked on credit to a client that does credit while it uploads ended with no RST_STREAM(NO_ERROR) after its END_STREAM, the upload then credited nothing, so that request never completed. - Http2ResponseWriter.CompleteAsync no longer waits for the peer's credit: what the windows cannot take yet goes out in the background as credit arrives, END_STREAM last, and the stream is retired behind it. A buffered rest parked on credit takes the same path. - A stream whose handler is done while its answer waits on credit stays open behind it: what the handler left unread is credited and dropped, as the nghttp2 twin's reader does, and DATA still arriving is credited as it lands, still held to its stream window and content-length. - Once that answer's END_STREAM is out, a request still arriving is reset with NO_ERROR after it, as an answer that ends at once already is. - HandleData's crediting of DATA for a stream that had left the table under a parked buffered rest is gone: such a stream now stays in the table. IsCompleted is true once CompleteAsync has returned, its end possibly still waiting on credit, and a FlushAsync after CompleteAsync reports IsCompleted. A handler that waits on FlushAsync for that credit, its body unread, still waits until such a client gives up; Http2BodyReader's docs say so. Tests: Unit Http2EarlyAnswerParkedTests on the wire, and E2E EarlyAnswerTests with .NET's HttpClient over h2c, non-duplex and duplex, each failing at origin/main or with its part of the fix reverted.
This was referenced Nov 14, 2026
This was referenced Nov 14, 2026
Owner
Author
|
Closed: the clean close it added (RST_STREAM(NO_ERROR) after an answer that waited on the client's credit) is now in #633. The rest, draining the upload of a client that reads only after it has sent everything, is not something the server will do: such a client waits until its own timeout, as it would with nginx or Go. |
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.
Part of #588.
What was wrong
RFC 9113 8.1 lets a server send a complete response before the client has sent its whole request. A client that reads its response only once its upload has ended, as .NET's
HttpClientdoes with a content that is not duplex, also credits the response only then. ioxide.http2 credits a request's stream only as its handler reads the body, so a handler that answered without reading left the upload holding the server's stream window (InitialWindowSize, 256 KiB by default). An answer past the client's stream window (65,535 for .NET) then waited on credit the client would give only after an upload the server would not take: neither side could move, and the request hung until the client gave up. Since the connection window was opened to 2^31-1, the threshold is the server's stream window: at origin/main an upload of 262,144 bytes is answered and one of 262,145 hangs, and it followsInitialWindowSize(65,535 and 1 MiB hang at exactly those sizes).Three handler shapes hung:
writer.CompleteAsync()(the issue's shape):CompleteAsyncwaited for the client's credit, so the handler never returned, nothing was credited, and the RST_STREAM(NO_ERROR) that follows an early answer's END_STREAM never went out;A related gap with a client that does credit while it uploads: a buffered answer parked on credit sent its END_STREAM with no RST_STREAM(NO_ERROR) after it, and the stream was credited nothing from then on, so the upload stalled and the request never completed.
What changes
All in
src/protocols/ioxide.http2; no core change, no native change.Http2ResponseWriter.CompleteAsyncno longer waits for the peer's credit. What the windows cannot take yet goes out in the background as credit arrives, END_STREAM last, from the writer's own staging, and the connection retires the stream behind it. A buffered response's rest parked on credit takes the same path, so the two share one tail.HandleDatano longer credits DATA for a stream that has left the table because a buffered rest is parked: that stream now stays in the table, so the special case is gone.Removed: the private
CompleteParkedAsync, replaced by the shared tail.Behaviour a caller would notice
CompleteAsyncreturns before the client's credit for the end has arrived.IsCompletedis true once it has returned, even while its END_STREAM still waits on credit.ResetStreamAsyncafter that sends nothing, as after any completion.FlushAsyncafterCompleteAsyncnow reportsIsCompleted; it used to flush nothing and report the response live, and with the end parked it would have waited on the same credit, over the staging the parked end sends from.Not fixed, and documented on
Http2BodyReader: a handler that waits onFlushAsyncfor credit while not reading its body still waits until such a client gives up. Nothing can be credited while the handler may still read the body; the nghttp2 twin behaves the same. That case is why this PR is "Part of": merging it leaves #588 open for it.Tests
Unit,
Http2EarlyAnswerParkedTests, on the wire with the strict client (a 131,070-byte answer, twice the client's 65,535 window; the upload fills the server's 256 KiB stream window):CompleteAsyncreturns without the client's credit, and the unread upload is credited once the handler returns, the same way;CompleteAsyncparked its answer gets all of it, credited once (nothing is drained from under a handler still running);FlushAsyncafterCompleteAsyncparked the answer reports it ended, and the answer goes out once;E2E,
EarlyAnswerTests, .NETHttpClientover h2c posting 64 MiB to a handler that answers a 256 KiB 413 unread:StreamContent: a streamed answer whose handler returnsCompleteAsync, one left to the stack's completion, and a buffered one returned once the upload had stalled each arrive whole, and the upload ends at its last byte;HttpContent: a buffered and a streamed answer arrive whole, and the upload stops under 32 MiB (measured up to 2.5 MiB);Changed:
Http2FlowControlTests' "a writer parked on credit is released when the peer closes the connection cleanly" parks its handler onFlushAsync, sinceCompleteAsyncno longer waits for credit and the test would otherwise pass without a parked handler.Confirmed both ways. With
src/protocols/ioxide.http2at origin/main and the new tests in place:Each part reverted on its own, the rest of the fix in place:
CompleteAsyncwaiting for credit again: 5 unit tests fail ("CompleteAsync held the handler...", "the handler read 0 of the 262144 bytes...", "...returned nothing, still waiting on credit", "...262144 bytes unread and 0 came back" for the stack's completion, "expected [17384], got [0]"), and the two streamed non-duplex E2E tests ("the answer never arrived ... 327680 of 67108864 bytes").FlushAsyncafter completion taking up the staging again: "a flush after the response had completed returned nothing, still waiting on credit".Suites
Pinned to the safe CPUs, on the final tree:
File, Pg and Redis were not run: nothing they cover changed.
For the reviewer
RetireStream's guard against resetting a stream whose answer is still parked stays: the tail removes the answer's window before it retires the stream, so the reset follows the END_STREAM.CompleteAsyncreturned was already a misuse; with the end parked such bytes join the parked rest instead of being dropped.HandleData.DispatchBufferedandCompleteBufferedAsync(keep its catch that writes the 500, and retire throughRetire(pending, parked)as here) and with http3: ioxide.http3 lets a client upload the rest of a body its handler answered without reading #587's inEarlyAnswerTests.cs(both add tests and helpers: keep both).FlushCoreandPushand a null test where a stream is retired; only an answer out of credit takes the parked path, which is out of line and allocates oneTaskper parked end.