runtime: Unobserved task exception

I’m not 100% sure where the offending code is, but I’ve seen many instances of these in my telemetry. This is with .NET Core 3

https://github.com/dotnet/coreclr/tree/5ec1eeaa95362be9e76f9f79c9b44162

My code calls Read() on a contained Stream instance, the rest is BCL code:

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: The I/O operation has been aborted because of either a thread exit or an application request..) ---> System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request.. ---> System.Net.Sockets.SocketException: The I/O operation has been aborted because of either a thread exit or an application request.
   at Bugsnag.UnhandledException.HandleEvent(Exception exception, bool runtimeEnding)
   at Bugsnag.UnhandledException.TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
   at System.Threading.Tasks.TaskScheduler.PublishUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs ueea)
   at System.Threading.Tasks.TaskExceptionHolder.Finalize()   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.ThrowException(SocketError error)
   at System.Net.Sockets.Socket+AwaitableSocketAsyncEventArgs.GetResult(short token)
   at System.Net.Security.SslStreamInternal+<<FillBufferAsync>g__InternalFillBufferAsync|38_0>d<TReadAdapter>.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Net.Security.SslStreamInternal+<ReadAsyncInternal>d__34<TReadAdapter>.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.HttpConnection+<ReadAsync>d__85.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.HttpConnection+ContentLengthReadStream+<ReadAsync>d__2.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.BaseAsyncStream.Read(byte[] buffer, int offset, int count)
   at PackageExplorer.ProgressStream.Read(byte[] buffer, int offset, int count) in PackageExplorer\MefServices\PackageDownloader.cs:line 275
   at System.IO.Stream+<>c.<BeginReadInternal>b__43_0(object <p0>)
   at System.Threading.Tasks.Task<TResult>.InnerInvoke()
   at System.Threading.Tasks.Task+<>c.<.cctor>b__277_0(object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, object state)
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref Task currentTaskSlot, Thread threadPoolThread)   --- End of inner exception stack trace ---
   at Bugsnag.UnhandledException.HandleEvent(Exception exception, bool runtimeEnding)
   at Bugsnag.UnhandledException.TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
   at System.Threading.Tasks.TaskScheduler.PublishUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs ueea)
   at System.Threading.Tasks.TaskExceptionHolder.Finalize()

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (21 by maintainers)

Commits related to this issue

Most upvoted comments

As aside might want to override the XxxAsync methods of ProgressStream to call through to the Stream _inner async methods; otherwise it will go via the sync overrides.

https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/blob/master/PackageExplorer/MefServices/PackageDownloader.cs#L248-L302

and never actually exposed to the caller

It is, via EndRead, no? If the End corresponding to the Begin isn’t called that’s a bug in the using code.