Repository navigation
[release/11.0] Fix HTTP/2 hang on reused streams when a window update races the final write - #70099
Merged
Merged
Conversation
…9690) Http2FrameWriter skipped producers whose response had already completed without clearing Http2OutputProducer._isScheduled. A stream WINDOW_UPDATE racing a response's final write can schedule the producer again after ObserveDataAndState cleared the flag, so that queue entry was dropped with the flag still set. StreamReset doesn't reset the flag, so the next request that reused the pooled stream could never schedule its HEADERS, DATA or trailers, and its aborts were never processed. Unschedule a completed producer under its lock when the frame writer skips it, and continue with the next producer. Co-authored-by: Copilot App <[email protected]> Co-authored-by: Stephen Halter <[email protected]>
github-actions
Bot
requested review from
BrennanConroy,
SamMonoRT and
halter73
as code owners
October 29, 2026 17:43
This was referenced Oct 31, 2026
halter73
approved these changes
Nov 10, 2026
Contributor
|
Hi @github-actions[bot]. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
Contributor
|
Hi @github-actions[bot]. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #69690 to release/11.0
/cc @halter73 @danield137
Fix HTTP/2 hang on reused streams when a window update races the final write
Unschedule completed HTTP/2 producers before pooled streams are reused.
Description
A stream WINDOW_UPDATE racing the final response write can leave an extra entry in Kestrel's HTTP/2 output queue. The writer discards that entry after the response completes without clearing the producer's
_isScheduledflag. If the stream is pooled and reused, subsequent scheduling attempts return early and the new response is never sent.Clear
_isScheduledwhen dequeuing and skipping a completed producer. The completion check and flag update use the same lock asSchedule(). Preserve the existing scheduling token when the stream has already been reused. Include regression coverage for scheduling both after response completion and during the final write.Fixes #53736
Customer Impact
Intermittent HTTP/2 requests, including gRPC calls, can hang without receiving response headers while other requests on the same connection continue working. Larger responses can also leave server-side response writes blocked. Multiple customers have reported the issue, including after upgrading from .NET 6.
Increasing the client's initial HTTP/2 stream window can mitigate the issue for responses smaller than that window, but requires control of every affected client and is not a general server-side workaround.
Regression?
Regressed from .NET 6 in .NET 7 with #40925, which introduced the shared HTTP/2 output scheduling mechanism. The affected code remains in release/11.0.
Risk
The change is limited to the existing completed-producer discard path. It repairs scheduling bookkeeping without changing public APIs, normal response processing, or pooling policy. The previous completion-property check already acquired the same lock, so the change does not add a lock acquisition to each dequeue. The product patch is identical to the fix merged in #69690.
Verification
Manual end-to-end: Ran a standalone Kestrel h2c server and
SocketsHttpHandlerclient over real loopback sockets on Windows x64, using the 64 KiB echo workload from the issue. Each run used 120,000 POST requests, 16 concurrent requests, one HTTP/2 connection, the default 65,535-byte initial client stream window, dynamic window sizing, and a five-second per-request timeout. No scheduling events were injected and no Kestrel state was modified at runtime. Successful responses were checked for HTTP/2, successful status, and byte-for-byte echo correctness._isScheduledalready true; it remained true and_completedResponseremained false when the requests timed out. The other 119,968 requests completed successfully on the same connection.Automated: The original three regression cases in
Http2ConnectionTestspassed with the fix:StreamPool_ScheduledAfterResponseCompleted_PooledStreamReusedAndResponseSent(bothlargeResponsevalues) andStreamPool_ScheduledDuringFinalWrite_PooledStreamReusedAndResponseSent. Previously, all three cases timed out at the reused stream's response HEADERS without the fix in 33 runs each (99 individual executions).Packaging changes reviewed?
No packaging changes. Only two Kestrel implementation files and the existing functional-test file are changed.