Skip to content

Fix PipeReader contract violation in DefaultHttpRequestParser#9761

Merged
tobias-tengler merged 2 commits into
mainfrom
tte/fix-pipereader-usage-in-request-parser
May 21, 2026
Merged

Fix PipeReader contract violation in DefaultHttpRequestParser#9761
tobias-tengler merged 2 commits into
mainfrom
tte/fix-pipereader-usage-in-request-parser

Conversation

@tobias-tengler
Copy link
Copy Markdown
Member

Closes #9759

Copilot AI review requested due to automatic review settings May 21, 2026 12:42
Copy link
Copy Markdown
Contributor

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 PipeReader contract violation in DefaultHttpRequestParser that could leave a final successful ReadAsync un-advanced when parsing fails, triggering intermittent InvalidOperationException (“Reading is already in progress”) during Kestrel request-body draining on HTTP/1.1 (Issue #9759).

Changes:

  • Refactors request body reading into a shared ReadFullBodyAsync loop and ensures the final ReadResult is always followed by AdvanceTo(...) via try/finally (even on syntax/parse errors).
  • Preserves existing request size enforcement while ensuring AdvanceTo is called on the oversize path.
  • Adds tests covering syntax error and canceled read scenarios to validate the reader is left in a readable state after failures.

Reviewed changes

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

File Description
src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Parsers/DefaultHttpRequestParser.cs Ensures the final successful ReadAsync is always advanced (via finally) and centralizes “read full body” logic to honor PipeReader contract on all exit paths.
src/HotChocolate/AspNetCore/test/AspNetCore.Tests/Serialization/DefaultHttpRequestParserTests.cs Adds regression tests that attempt subsequent reads after failure/cancel to catch the prior “reading already in progress” behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

ConnectionAbortedException: "Reading is already in progress" race in DefaultHttpRequestParser on HTTP/1.1

2 participants