runtime: HTTP2 connection hangs and causes TaskCanceledException in System.Net.Http.HttpConnectionPool
Description
In our forked version of YARP we are encountering an issue where an HTTP/2 connection request to just one of many destination endpoints fails consistently, resulting in a TaskCanceledException after just under 1 second into attempting to send a request to a remote end point. The connection seems to be stuck waiting for a settings frame that is never received, which is similar to the situation discussed in this issue. Once the process enters this state, the only solution to the issue is to restart it. We are contemplating recycling of the SocketsHttpHandler instance as an alternative, but until the issue is not understood that would be a premature thing to do.
This issue typically arises after the process that owns the proxy destination endpoint restarts while the proxy itself remains running.
The HttpClient instance in our proxy server uses a static SocketsHttpHandler instance with a 4-minute timeout for the pooled HTTP connections inside the SocketsHttpHandler. However, the timeout does not seem to matter because we are unable to establish an HTTP/2 connection in the first place.
We are currently running the latest release of .NET 8.
We’re unsure if this issue is a bug in the framework or something in our code.
Could you help us identify where we should begin investigating to understand the root cause of this error? For example, could it be related to the inability to resolve DNS on the first connection attempt due to DNS caching?
Thank you!
Reproduction Steps
None
Expected behavior
A clear error that unambiguously describes why a request can not be sent or the connection can not be established.
Actual behavior
The following exception:
System.Threading.Tasks.TaskCanceledException: A task was canceled.
---> System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
at ... some method of ours ....
Regression?
Potentially: this started with .NET 8 upgrade (from .NET 7)
Known Workarounds
None
Configuration
- Ubuntu 20.04
- .NET 8
- A docker container running in a load balancer VM instance.
Other information
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 28 (12 by maintainers)
you can send email with file location to my GH email @brucremo. I was out last week and I’m catching up.
To follow-up on the discussion above: if this is TCP closing issue, we should see it in the packet capture. It is difficult for HttpClient to detect TCP failure of OS does not report them.
there would be some setting about client certificates… If you flip to TLS 1.2 you would see renegotiation request after handshake. For TLS 1.3 everything is encrypted so much more difficult to diagnose. Still, if you get packet captures one can guess based on packet sequence.