Skip to content

Stop the HTTP/1 request loop when the connection is aborted - #10225

Merged
wtgodbe merged 1 commit into
mainfrom
wtgodbe/port-e1190e4-main
Oct 14, 2026
Merged

wtgodbe merged 1 commit into
mainfrom
wtgodbe/port-e1190e4-main

Conversation

@wtgodbe

@wtgodbe wtgodbe commented Oct 14, 2026

Copy link
Copy Markdown
Member

Connection completion can set _connectionAborted without clearing _keepAlive. Request cleanup then skips body draining, but the request loop can parse unread body bytes as another request.

This change clear _keepAlive before the volatile write to _connectionAborted so cleanup that observes the abort also observes persistence disabled. Keep _keepAlive as the sole request-loop condition and remove the unused OnRequestProcessingEnding hook.

Customer Impact

Prevents an aborted HTTP/1 connection from treating unread request-body bytes as a subsequent request, avoiding request desynchronization and unintended request dispatch after connection completion.

Regression?

  • Yes
  • No

The regression was introduced by aspnet/KestrelHttpServer#2977.

Risk

  • High
  • Medium
  • Low

The change is small and localized to Kestrel connection-abort ordering. The regression test covers the security-relevant case where unread request-body bytes resemble another request.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

… connection is aborted

Connection completion can set _connectionAborted without clearing _keepAlive. Request cleanup then skips body draining, but the request loop can parse unread body bytes as another request.

This change clear _keepAlive before the volatile write to _connectionAborted so cleanup that observes the abort also observes persistence disabled. Keep _keepAlive as the sole request-loop condition and remove the unused OnRequestProcessingEnding hook.

## Customer Impact

Prevents an aborted HTTP/1 connection from treating unread request-body bytes as a subsequent request, avoiding request desynchronization and unintended request dispatch after connection completion.

## Regression?

- [x] Yes
- [ ] No

The regression was introduced by aspnet/KestrelHttpServer#2977.

## Risk

- [ ] High
- [ ] Medium
- [X] Low

The change is small and localized to Kestrel connection-abort ordering. The regression test covers the security-relevant case where unread request-body bytes resemble another request.

## Verification

- [X] Manual (required)
- [x] Automated

## Packaging changes reviewed?
- [ ] Yes
- [ ] No
- [x] N/A

----

#### AI description  (iteration 1)
#### PR Classification
Bug fix to prevent HTTP/1 connections from incorrectly parsing unread request body data as new requests when the connection is aborted.

#### PR Summary
This pull request fixes a bug where HTTP/1 request processing would continue and attempt to parse remaining data in the request body as a new request after the connection was aborted. The fix ensures the request loop terminates properly by disabling keep-alive before publishing the abort signal.

- `HttpProtocol.cs`: Sets `_keepAlive` to false before setting `_connectionAborted` to ensure the request loop observes the disabled keep-alive state and stops processing
- `HttpProtocol.cs`: Removes the unused `OnRequestProcessingEnding()` virtual method and related cleanup logic
- `RequestTests.cs`: Adds test `InputCompletionDoesNotReparseUnreadRequestBody()` to verify that a GET request embedded in a POST body is not dispatched when the connection is aborted
- `Http1Connection.cs`: Removes the empty override of `OnRequestProcessingEnding()`
<!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot -->

Co-authored-by: Copilot <[email protected]>
@wtgodbe
wtgodbe requested review from halter73 and a balanced review from Copilot October 14, 2026 16:10
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team October 14, 2026 16:10
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟢 Approval recommended

The ordering fix is localized, memory-safe, and covered by a faithful regression test.

0 open findings

What changed in this PR

Stops the HTTP/1 request loop after connection abortion so unread body bytes cannot be parsed as another request.

Changes:

  • Disables keep-alive before publishing the abort state.
  • Adds regression coverage for unread request bodies.
  • Removes an unused processing hook.
File Description
HttpProtocol.cs Orders keep-alive shutdown before abort publication.
Http1Connection.cs Removes the unused override.
RequestTests.cs Verifies unread body bytes are not redispatched.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@wtgodbe
wtgodbe merged commit 388e4e6 into main Oct 14, 2026
12 checks passed
@wtgodbe
wtgodbe deleted the wtgodbe/port-e1190e4-main branch October 14, 2026 21:44
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.

3 participants