runtime icon indicating copy to clipboard operation
runtime copied to clipboard

HttpIOException when establishing connection, unobserved task exception

Open mattchidley opened this issue 2 years ago • 3 comments

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

mattchidley avatar May 28 '24 17:05 mattchidley

Can you share the stack trace of those unobserved exceptions?

MihaZupan avatar May 28 '24 19:05 MihaZupan

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 Http2Connection.ReadFrameAsync(bool initialFrame)+ThrowMissingFrame() throw new HttpIOException(HttpRequestError.ResponseEnded, SR.net_http_invalid_response_missing_frame); File "Http2Connection.cs", line 417, in async ValueTask Http2Connection.ReadFrameAsync(bool initialFrame) ThrowMissingFrame(); File "Http2Connection.cs", line 477, in async Task Http2Connection.ProcessIncomingFramesAsync() frameHeader = await ReadFrameAsync(initialFrame: true).ConfigureAwait(false);

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.

mattchidley avatar May 29 '24 14:05 mattchidley

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.

MihaZupan avatar May 29 '24 14:05 MihaZupan