HttpIOException when establishing connection, unobserved task exception
Describe the bug
Ever since 8.0.3 we've been seeing UnobservedTaskException: System.Net.Http.HttpIOException: An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake. (InvalidResponse)
We have not seen this before 8.0.3 with our current environment.
We are curious whether there has been a change in the framework with how the handshake handles an unexpected connection termination with the host? These errors coincide with service disruption on the host.
Repro
While I can't provide a working sample because I think timing and load plays a key factor, our belief is that during client -> server connection negotiation the webserver is shutdown.
Exceptions (if any)
UnobservedTaskException: System.Net.Http.HttpIOException: An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake. (InvalidResponse)
Further technical details
We have observed this on .net 8.0.3, 8.04, and 8.0.5, we do not see this on 8.0.2 or 7.0
Can you share the stack trace of those unobserved exceptions?
System.Net.Http.HttpIOException: The response ended prematurely while waiting for the next frame from the server. (ResponseEnded)
File "Http2Connection.cs", line 466, in ValueTask
System.Net.Http.HttpIOException: An HTTP/2 connection could not be established because the server did not complete the HTTP/2 handshake. (InvalidResponse) System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.
We're creating a new exception here to signal the InitialSettingsReceived TCS, which may never get observed.
https://github.com/dotnet/runtime/blob/23e15a51b8c45df8c5efbd5b80d577eaef981edb/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs#L505
This code has been there in a similar form since 8.0 preview 1 (#80066), so not an 8.0 servicing regression. It's a bug we should fix (same as other places where we might throw unobserved exceptions), but should be functionally benign.