Repository navigation
Track HTTP/2 pools when connection timeout is zero - #136656
RutulPatel8 wants to merge 3 commits into
Conversation
|
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. |
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
| settings._keepAlivePingDelay == Timeout.InfiniteTimeSpan && | ||
| // HTTP/2 and HTTP/3 may pool a new connection before its first request completes. | ||
| // Keep their pools tracked so handler disposal can close those connections. | ||
| settings._maxHttpVersion.Major == 1; |
There was a problem hiding this comment.
I think this would effectively kill this optimization in practice.
A better alternative approach may be to check for this edge case as part of returning an H2 connection to the pool.
There was a problem hiding this comment.
Thanks, you are right: gating the optimization on the maximum HTTP version disables it for most default handlers. I pushed 8d455703d2c, which restores the original manager condition and handles the untracked-pool case in ReturnHttp2Connection. The connection is removed from pooling, and its shutdown waits for streams already assigned to it so the first request can still send. Both the library and functional test projects build with zero warnings/errors; CI is running for the new commit. @MihaZupan, could you take another look when it finishes?
| { | ||
| Debug.Assert(_poolManager.AvoidStoringConnections); | ||
| if (NetEventSource.Log.IsEnabled()) connection.Trace("Disposing HTTP2 connection when its assigned streams complete. Pool is untracked."); | ||
| connection.DisposeWhenIdle(); |
There was a problem hiding this comment.
Is this different from calling the existing Shutdown? Why do we need to track the extra _disposeWhenIdle?
There was a problem hiding this comment.
Shutdown() sets _shutdown immediately. A waiter can already have been given a stream reservation on the newly created connection; its request checks _shutdown before opening the stream and would then retry on another connection. _disposeWhenIdle blocks new reservations while letting those already assigned finish, and calls Shutdown() after the last reservation is released. I also updated the waiter assertion in 87b80e7 to account for that intermediate state. Please let me know if you see a simpler way to retain the assigned request.
Summary
With a zero pooled connection lifetime or idle timeout,
HttpConnectionPoolManageromits its cleanup timer and does not track pools. A newly created HTTP/2 connection can still reach the pool's return path and remain cached there, so disposing the handler misses it.Keep the existing no-storage optimization. When an HTTP/2 connection returns to an untracked pool, do not cache it. Defer its shutdown until all streams already assigned to it have finished, including the first request that may not have started sending when the connection is returned.
Add an HTTP/2 regression test for zero lifetime and zero idle timeout. It completes a request, disposes the handler, and waits for a client-initiated disconnect.
Fixes #135997.
Validation
System.Net.Http.csprojRelease build: passed with zero warnings and errors.System.Net.Http.Functional.Tests.csprojRelease build: passed with zero warnings and errors.git diff --check: passed.dotnet.exeand runtime files. The first CI run passed Build Analysis and reported one known unrelated HTTP/3 timeout (System.Net.Http.Functional.Tests.SocketsHttpHandler_DiagnosticsTest_Http3.SendAsync_ReuseRequestInHandler_ResetsHeadersForEachReuse: System.TimeoutException #132085); the follow-up commit needs a fresh run.