Skip to content

[release/10.0] Fix HTTP/2 hang on reused streams when a window update races the final write - #70100

Merged
wtgodbe merged 1 commit into
release/10.0from
backport/pr-69690-to-release/10.0
Nov 16, 2026
Merged

wtgodbe merged 1 commit into
release/10.0from
backport/pr-69690-to-release/10.0

Conversation

@github-actions

@github-actions github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Backport of #69690 to release/10.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 _isScheduled flag. If the stream is pooled and reused, subsequent scheduling attempts return early and the new response is never sent.

Clear _isScheduled when dequeuing and skipping a completed producer. The completion check and flag update use the same lock as Schedule(). 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?

  • Yes
  • No

Regressed from .NET 6 in .NET 7 with #40925, which introduced the shared HTTP/2 output scheduling mechanism. The affected code remains in release/10.0.

Risk

  • High
  • Medium
  • Low

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 (required)
  • Automated

Manual end-to-end: Ran a standalone Kestrel h2c server and SocketsHttpHandler client 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.

  • Without the writer-loop fix: 32 of 120,000 requests hung before receiving response headers. All 32 reached the server handler with _isScheduled already true; it remained true and _completedResponse remained false when the requests timed out. The other 119,968 requests completed successfully on the same connection.
  • With the fix: 0 hangs in 240,000 requests across two runs. Every response body matched the request, all handlers completed, and server shutdown completed in both runs.

Automated: The original three regression cases in Http2ConnectionTests passed with the fix: StreamPool_ScheduledAfterResponseCompleted_PooledStreamReusedAndResponseSent (both largeResponse values) and StreamPool_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?

  • Yes
  • No
  • N/A

No packaging changes. Only two Kestrel implementation files and the existing functional-test file are changed.

…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]>
@danield137

Copy link
Copy Markdown
Contributor

@halter73 we are waiting on this backport to deploy in production. Please review as soon as possible

@halter73 halter73 added the Servicing-consider Shiproom approval is required for the issue label Nov 10, 2026
@dotnet-policy-service

Copy link
Copy Markdown
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.

@danield137

Copy link
Copy Markdown
Contributor

@JamesNK / @BrennanConroy seems like a second approver is needed?

@wtgodbe wtgodbe added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Nov 16, 2026
@dotnet-policy-service

Copy link
Copy Markdown
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.

@wtgodbe
wtgodbe merged commit 9185b70 into release/10.0 Nov 16, 2026
31 checks passed
@wtgodbe
wtgodbe deleted the backport/pr-69690-to-release/10.0 branch November 16, 2026 22:07
@dotnet-policy-service dotnet-policy-service Bot added this to the 10.0.14 milestone Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Servicing-approved Shiproom has approved the issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants