-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Description
If the SocketsHttpHandler is not disposed, HttpConnection.Dispose will not be called in time to observe the exception from the readAheadTask. The Dispose will run as part of the finalizer, but since the TaskExceptionHolder in _readAheadTask is also finalizable, it may be too late as the execution order of finalizers is not guaranteed.
Impact: Noise
The exceptions that leak to UnobservedTaskExceptions would be ignored anyway, so there is no adverse side effects aside from noise.
I am able to reproduce the same thing on 5.0 as well. The code is pretty much the same on 3.1, so I assume it would repro there as well (haven't tried since I am relying on the ConnectCallback).
Example 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. (Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..)
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](TIOAdapter adapter, Memory`1 buffer)
at System.Net.Http.HttpConnection.<CheckUsabilityOnScavenge>g__ReadAheadWithZeroByteReadAsync|44_0()
--- End of inner exception stack trace ---
davidni