Defer WinHTTP HTTP/2 loopback connection closure until server disposal - #134181
Merged
rzikm merged 1 commit intoSep 18, 2026
Merged
Conversation
Keep retired connections open until the enclosing loopback server is disposed so WinHTTP can consume buffered responses before receiving FIN. Preserve explicit shutdown behavior, cover deferred disposal and teardown races, and re-enable HTTP/2 cookie tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two moderate concurrency and cleanup-safety issues remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
This PR defers WinHTTP HTTP/2 loopback connection closure until server disposal, preserving buffered responses and re-enabling affected cookie tests.
Changes:
- Adds deferred disposal, GOAWAY tracking, and cleanup regression tests.
- Re-enables WinHTTP HTTP/2 cookie tests.
- Updates shared loopback connection lifecycle handling.
File summaries
| File | Summary |
|---|---|
src/libraries/System.Net.Http.WinHttpHandler/tests/FunctionalTests/WinHttpHandlerTest.cs |
Adds deferred-disposal regression tests. |
src/libraries/System.Net.Http.WinHttpHandler/tests/FunctionalTests/PlatformHandlerTest.cs |
Re-enables HTTP/2 cookie tests. |
src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs |
Manages retained connections and server cleanup. Moderate finding (1 vote): deferred-close state visibility is unsynchronized. |
src/libraries/Common/tests/System/Net/Http/Http2LoopbackConnection.cs |
Implements deferred GOAWAY and closure behavior. Moderate finding (2 votes): concurrent field cleanup can race active I/O and cause NullReferenceException. |
Review details
Suppressed comments (1)
src/libraries/Common/tests/System/Net/Http/Http2LoopbackServer.cs:94
IsCloseDeferredis read under the server's_connectionslock, but_closeDeferredis written byHttp2LoopbackConnection.DisposeAsyncwithout that lock and is a plainbool. The lock therefore does not establish visibility between a completed deferred disposal and a concurrentEstablishConnectionAsync, so the new-connection path can still observefalseand throwConnection already established. Synchronize this state transition (for example with matchingVolatile.Read/Volatile.Write, or by using the server lock for both sides).
if (!AllowMultipleConnections && _connections.Exists(c => !c.IsCloseDeferred))
- Files reviewed: 4/4 changed files
- Comments generated: 1
- Review effort level: Lite
This was referenced Sep 18, 2026
ManickaP
approved these changes
Sep 18, 2026
Member
Author
|
/ba-g only known errors |
rzikm
enabled auto-merge (squash)
September 18, 2026 15:51
Member
Author
|
/backport to release/11.0 |
Contributor
|
Started backporting to |
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.
WinHTTP can discard buffered response data when the loopback server sends FIN before the client consumes it, causing error 12030. This affects more than cookie tests: the same failure signature also appeared in
ClientCertificateTest.UseClientCertOnHttp2_OSSupportsIt_Success. Synchronizing individual tests leaves other paths exposed.This change moves lifetime management into the shared HTTP/2 loopback infrastructure. In WinHTTP tests, connection disposal sends GOAWAY but retains the transport until the enclosing server is disposed, normally after both client and server callbacks complete. Retired connections do not prevent subsequent connections from being accepted. Automatic GOAWAY respects earlier last-stream boundaries, and cleanup tolerates the server closing a connection during asynchronous disposal.
The behavior is enabled by default only for WinHTTP tests. Explicit shutdown methods remain immediate, and tests requiring the original disposal behavior can set
DeferConnectionClose = false. The HTTP/2 cookie tests quarantined under #126867 are re-enabled; no cookie-specific synchronization or product code changes are needed.Validation
Fixes #133779
Fixes #130458
Fixes #126867
... and countless others that boil down to "Error 12030 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, 'The connection with the server was terminated abnormally'."
Note
This pull request description and changes were generated with GitHub Copilot.