Skip to content

http3: a response that ends before its request asks the client to stop sending the rest (#587) - #601

Merged
MDA2AV merged 2 commits into
mainfrom
fix-587
Nov 15, 2026
Merged

MDA2AV merged 2 commits into
mainfrom
fix-587

Conversation

@MDA2AV

@MDA2AV MDA2AV commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Fixes #587.

A handler that takes a body reader runs at end-of-headers, before its body has arrived. When it answered first (a 401, a 413, a redirect), ioxide.http3 retired the body: RetireBody unpaced the request stream, and FeedRequest dropped and credited every byte that kept arriving. Nothing asked the client to stop, so it uploaded the whole body for nothing: a 64 MiB POST answered with a 413 its handler never read still sent all 64 MiB, and the shim's raw client sent its whole 4 MiB budget. RFC 9114 4.1 lets a server that does not need the rest of the request abort reading the request stream, with H3_NO_ERROR, and says that a client whose request is not aborted SHOULD keep sending it. #582 did this for ioxide.http2 and ioxide.nghttp3; the pure C# stack kept reading.

The change. All in src/protocols/ioxide.http3, mirroring nghttp3's StopReadingIfAnsweredEarly:

  • Once the response is handed over, StopReadingIfAnsweredEarly calls QuicConnection.StopReading(streamId, H3_NO_ERROR): STOP_SENDING alone, so the response still goes out whole. It runs where nghttp3's does: after the Submit of a buffered answer, whether its handler returned, threw or awaited, and after a streamed writer's CompleteAsync or FailAsync.
  • No new flag, counter or list: existing state gates it. Nothing is sent for a request whose fin arrived or that this side reset (ReqStream.Finished), one the client reset or whose stream closed (no longer in _requests), or on a connection that is gone (IsBroken).
  • A streamed handler that fails after its headers is still reset both ways with H3_INTERNAL_ERROR. Its writer now resets through the new internal Http3Connection.ResetResponse, which marks the request Finished as Refuse does, so no STOP_SENDING follows that reset.
  • A client that refused the answer with its own STOP_SENDING is still asked to stop uploading once its handler returns, as on nghttp3.

No change to src/ioxide (QuicConnection.StopReading exists since #582) and none to the native shims, so nothing is rebuilt.

What a caller notices. A client uploading to a body-reader handler that answers before the body ends now gets STOP_SENDING(H3_NO_ERROR) on the request stream once the answer is handed over, and stops: .NET's HttpClient stops at 192 KiB of 64 MiB, as it does against nghttp3, and the raw client at 0 bytes. The answer still arrives whole. No public API changes.

Tests.

  • Http3EarlyAnswerTests (E2E, new), on a transport that logs what the stack asks of it on the request stream, in order, with every await inline:
    • claims, each ending in stop 0x100 after the answer's last send: a buffered answer (send, send+fin, stop 0x100), the 500 of a buffered handler that threw at once (send+fin, stop 0x100), a buffered answer its handler awaited, a streamed answer, the 500 of a streamed handler that failed before its headers, and a client that refused the answer (send, send, stop 0x100);
    • controls: a buffered and a streamed answer to an upload that ended get no stop;
    • guards: an upload the client reset gets none; a streamed handler that fails after its headers is reset once and gets none (send, send, reset 0x102); a request that arrives with its connection's close gets none.
  • EarlyAnswerTests (E2E), on the wire with a real QuicEngine:
    • with the shim's raw client, so these run without msquic: a buffered and a streamed 413 to an upload still arriving arrive whole and the upload stops; a buffered 413 its handler finished off the reactor, which the stack submits from a reactor post outside the pass that read the request; and a client that refused the answer is still asked to stop once its handler returns;
    • with .NET's HttpClient over h3 (msquic, skipped without it): a streamed and a buffered 413 to a 64 MiB upload arrive whole and the upload stops, under the existing 1 MiB bar. Control: an 8 MiB upload its handler reads to the end is sent whole and answered;
    • the nghttp3 raw-client tests do what they did: their client steps moved into two helpers the ioxide.http3 copies share, and StartH3 and StartHttp3 share one engine setup.

Seen failing without the fix, with the new tests in place:

  • With src/protocols/ioxide.http3 at origin/main, the six recorded claims fail with expected [send, send+fin, stop 0x100], got [send, send+fin] (got [send+fin] for the buffered 500, got [send, send] for the refused client). The four raw-client claims fail with the client uploaded 4194304 bytes to a handler that read none of them: nothing asked it to stop (4194304 more bytes after the handler returned for the refused client), and both HttpClient claims with the client uploaded 67108864 of 67108864 bytes. Controls and guards pass.
  • Each call site removed on its own fails only its own tests. After the immediate answer: the recorded buffered claim, the raw buffered and the HttpClient buffered. After the immediate 500: its recorded claim. After the awaited answer: its recorded claim and the off-reactor raw test. After CompleteAsync: the recorded streamed and refused claims, the raw streamed and refused, and the HttpClient streamed. After FailAsync: the recorded streamed 500.
  • Each guard removed on its own: without Finished, both controls end in stop 0x100, and the failure after headers in reset 0x102, stop 0x100. Without the _requests check, the client-reset guard ends in stop 0x100; without IsBroken, the closing-connection guard does. With ResetResponse not marking Finished, the failure after headers ends in reset 0x102, stop 0x100.

Suites, pinned to CPUs 0-3,6-7,14-31: Unit 263/0/0, E2E 748/0/0 (730 before plus the 18 new; msquic is installed, so the HttpClient h3 tests ran), Chaos 105/0/0 (its h3 cases run nghttp3, not this stack). The early-answer and recorded tests also passed 15 runs in a row, and H3StopSendingTests 3.

For review.

  • Order, as on nghttp3. A streamed answer's stop goes after CompleteAsync. If its last chunk waits on send capacity, the upload is unpaced and dropped for that wait; while the handler runs the stream is still paced, so only that final flush is exposed. Stopping right after RetireBody, once the headers are out, would close it, at the cost of parity.
  • A buffered answer whose body is parked on send capacity gets its stop as it is handed over, before the rest is on the wire. STOP_SENDING ends only the client's direction, and RFC 9114 4.1 orders it that way: abort reading, then send a complete response.
  • As on nghttp3, a body-reader request whose bare fin comes after its handler answered also gets the stop. ngtcp2 writes none when it has already seen that fin with all the data delivered.
  • ResetResponse marking Finished also means a fin still queued from before that reset is no longer parsed. It could only have led to a second reset, which ngtcp2 ignores, or, for a truncated last frame, an H3_FRAME_ERROR close over a stream this side had already abandoned.
  • At origin/main, 2 of 13 runs of the HttpClient pair failed one case with QuicException: ... QUIC_STATUS_INTERNAL_ERROR rather than the upload count. In the run whose server log was kept, the server had logged [ioxide.ngtcp2] recv queue overflow; closing connection. under the unpaced 64 MiB upload. It did not recur in 15 runs with the fix, where the upload stops.

…p sending the rest (#587)

A handler that takes a body reader runs at end-of-headers. When it answered before its body ended
(a 401, a 413, a redirect), RetireBody unpaced the request stream and FeedRequest dropped and
credited every byte that kept arriving, and nothing asked the client to stop: a 64 MiB POST answered
with a 413 its handler never read still uploaded all 64 MiB. RFC 9114 4.1 lets a server that does
not need the rest of a request abort reading it, with H3_NO_ERROR, and has the client keep sending
when it does not. #582 did this for ioxide.http2 and ioxide.nghttp3.

Once the response is handed over, ioxide.http3 now stops the request's read side with
QuicConnection.StopReading(streamId, H3_NO_ERROR), STOP_SENDING alone, at the points nghttp3 uses:
after the Submit of a buffered answer, whether its handler returned, threw or awaited, and after a
streamed writer's CompleteAsync or FailAsync. Existing state gates it: nothing for a request whose
fin arrived or that this side reset (ReqStream.Finished), one the client reset or whose stream
closed (gone from _requests), or a connection that is gone (IsBroken). A streamed handler that fails
after its headers is reset through the new Http3Connection.ResetResponse, which marks the request
Finished as Refuse does, so no STOP_SENDING follows that reset. A client that refused the answer
with its own STOP_SENDING is still asked to stop uploading once its handler returns.

No change to src/ioxide or the native shims: StopReading and iq_conn_shutdown_stream_read shipped
in #582.

Tests: E2E Http3EarlyAnswerTests pins what the stack asks of a recording transport, in order, for
each answer path, control and guard. E2E EarlyAnswerTests gains ioxide.http3 copies of the
raw-client and HttpClient tests. With the http3 sources at origin/main the claims fail ("got [send,
send+fin]", "uploaded 4194304 bytes", "uploaded 67108864 of 67108864 bytes"), and removing each call
site or guard on its own fails the test written for it.
# Conflicts:
#	tests/Ioxide.Tests.E2E/Protocols/EarlyAnswerTests.cs
@MDA2AV
MDA2AV merged commit 3b30d02 into main Nov 15, 2026
2 checks passed
@MDA2AV
MDA2AV deleted the fix-587 branch November 15, 2026 16:41
@MDA2AV MDA2AV mentioned this pull request Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

http3: ioxide.http3 lets a client upload the rest of a body its handler answered without reading

1 participant