Skip to content

System.Net.Quic is leaking UnobservedTaskExceptions #80111

Closed
@MihaZupan

Description

I have a console app with HttpClient that continuously sends requests to a localhost Kestrel instance.
If I randomly shut down and restart the server while HttpClient is making requests, I can see sporadic UnobservedTaskExceptions coming from System.Net.Quic.

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. (Operation aborted.)
 ---> System.Net.Quic.QuicException: Operation aborted.
   at System.Net.Quic.ResettableValueTaskSource.TryComplete(Exception exception, Boolean final) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\Internal\ResettableValueTaskSource.cs:line 157
   at System.Net.Quic.ResettableValueTaskSource.TrySetException(Exception exception, Boolean final) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\Internal\ResettableValueTaskSource.cs:line 221
   at System.Net.Quic.QuicStream.HandleEventShutdownComplete(_SHUTDOWN_COMPLETE_e__Struct& data) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicStream.cs:line 634
   at System.Net.Quic.QuicStream.HandleStreamEvent(QUIC_STREAM_EVENT& streamEvent) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicStream.cs:line 671
   at System.Net.Quic.QuicStream.NativeCallback(QUIC_HANDLE* connection, Void* context, QUIC_STREAM_EVENT* streamEvent) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicStream.cs:line 695
--- End of stack trace from previous location ---
   at System.Net.Quic.ResettableValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\Internal\ResettableValueTaskSource.cs:line 235
   at System.Net.Quic.QuicStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicStream.cs:line 306
   at System.Net.Http.Http3Connection.<>c__DisplayClass45_0.<<ProcessServerControlStreamAsync>g__ReadFrameEnvelopeAsync|0>d.MoveNext() in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http3Connection.cs:line 679
--- End of stack trace from previous location ---
   at System.Net.Http.Http3Connection.ProcessServerControlStreamAsync(QuicStream stream, ArrayBuffer buffer) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http3Connection.cs:line 624
   at System.Net.Http.Http3Connection.ProcessServerStreamAsync(QuicStream stream) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http3Connection.cs:line 520
   at System.Net.Http.Http3Connection.ProcessServerStreamAsync(QuicStream stream) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http3Connection.cs:line 575
   --- End of inner exception stack trace ---
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. (Operation aborted.)
 ---> System.Net.Quic.QuicException: Operation aborted.
   at System.Net.Quic.QuicConnection.HandleEventShutdownComplete() in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 492
   at System.Net.Quic.QuicConnection.HandleConnectionEvent(QUIC_CONNECTION_EVENT& connectionEvent) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 571
   at System.Net.Quic.QuicConnection.NativeCallback(QUIC_HANDLE* connection, Void* context, QUIC_CONNECTION_EVENT* connectionEvent) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 598
--- End of stack trace from previous location ---
   at System.Net.Quic.QuicConnection.AcceptInboundStreamAsync(CancellationToken cancellationToken) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 402
   at System.Net.Http.Http3Connection.AcceptStreamsAsync() in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Http3Connection.cs:line 438
   --- End of inner exception stack trace ---
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. (The server is currently unreachable.)
 ---> System.Net.Quic.QuicException: The server is currently unreachable.
   at System.Net.Quic.QuicConnection.HandleEventShutdownInitiatedByTransport(_SHUTDOWN_INITIATED_BY_TRANSPORT_e__Struct& data) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 470
   at System.Net.Quic.QuicConnection.HandleConnectionEvent(QUIC_CONNECTION_EVENT& connectionEvent) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 569
   at System.Net.Quic.QuicConnection.NativeCallback(QUIC_HANDLE* connection, Void* context, QUIC_CONNECTION_EVENT* connectionEvent) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 598
--- End of stack trace from previous location ---
   at System.Net.Quic.ValueTaskSource.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\Internal\ValueTaskSource.cs:line 176
   at System.Net.Quic.QuicConnection.FinishConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 312
   at System.Net.Quic.QuicConnection.ConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 68
   at System.Net.Quic.QuicConnection.ConnectAsync(QuicClientConnectionOptions options, CancellationToken cancellationToken) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Quic\src\System\Net\Quic\QuicConnection.cs:line 73
   at System.Net.Http.ConnectHelper.ConnectQuicAsync(HttpRequestMessage request, DnsEndPoint endPoint, TimeSpan idleTimeout, SslClientAuthenticationOptions clientAuthenticationOptions, CancellationToken cancellationToken) in C:\MihaZupan\runtime-debug\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\ConnectHelper.cs:line 120
   --- End of inner exception stack trace ---

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-System.Net.Quicbugin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions