Skip to content

Http3RequestStream: read EOS after trailers #117026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented Jun 25, 2025

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 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

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
Copy link
Contributor

@Copilot Copilot AI left a comment

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.

Copy link
Contributor

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

This comment was marked as outdated.

@antonfirsov
Copy link
Member Author

/azp run runtime-libraries stress-http

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants