Skip to content

Http3RequestStream: read EOS after trailers - #117026

Merged
antonfirsov merged 3 commits into
dotnet:mainfrom
antonfirsov:h3-trailers-read-eof-1
Jun 30, 2025
Merged

antonfirsov merged 3 commits into
dotnet:mainfrom
antonfirsov:h3-trailers-read-eof-1

Conversation

@antonfirsov

@antonfirsov antonfirsov commented Jun 25, 2025 •

Copy link
Copy Markdown
Contributor

This fixes the primary bug captured in #60118 without attempting to drain the stream and without touching the Dispose logic.

We expect trailers to be sent in a single HEADER frame, which is read by ReadHeadersAsync but that method doesn't read the EOS. Despite of that, we set _responseDataPayloadRemaining = -1 afterwards

goto case null;
case null:
// Done receiving: copy over trailing headers.
CopyTrailersToResponseMessage(_response!);
_responseDataPayloadRemaining = -1; // Set to -1 to indicate EOS.
return;

which then makes Http3RequestStream pretend that it reached EOS in subsequent read calls without ever trying to issue the read to the underlying QuicStream:

if (_responseDataPayloadRemaining == -1)
{
// EOS -- this branch will only be taken if user calls Read again after EOS.
return false;
}

This can be easily fixed by issuing one more read after reading the headers.

Copilot AI review requested due to automatic review settings June 25, 2025 17:56
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 25, 2025
@azure-pipelines

This comment was marked as outdated.

@antonfirsov antonfirsov added area-System.Net.Http and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 25, 2025
@antonfirsov antonfirsov added this to the 10.0.0 milestone Jun 25, 2025
@antonfirsov
antonfirsov requested a review from a team June 25, 2025 17:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where Http3RequestStream stopped reading the underlying QUIC stream after processing trailers, causing subsequent reads to immediately report end-of-stream. It refactors trailing-header handling into a new ProcessTrailersAsync method that issues one more read to detect EOS, and it updates both DrainContentLength0Frames and ReadNextDataFrameAsync to use this helper. A new regression test GetAsync_TrailersWithoutServerStreamClosure_Success is added to cover scenarios where trailers arrive without an explicit server stream closure.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs Extracted trailer processing into ProcessTrailersAsync and invoked an extra read to consume EOS.
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs Added a new theory-based Http3 regression test for reading trailers before stream closure; removed unused usings.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@azure-pipelines

This comment was marked as outdated.

@antonfirsov

Copy link
Copy Markdown
Contributor Author

/azp run runtime-libraries stress-http

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@ManickaP ManickaP left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@antonfirsov

Copy link
Copy Markdown
Contributor Author

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@antonfirsov
antonfirsov merged commit 0c7d43e into dotnet:main Jun 30, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants