We get the following AggregateException in the following piece of code, and we don't understand how we can catch this exception. The code is in a asp.net core SignalR server application.
Any suggestion?
public async Task MetricsStream(IAsyncEnumerable<ReadPointMetrics> stream)
{
try
{
await foreach (var metrics in stream) // this is line 224
{
try
{
await readerDeviceHub.StoreMetrics(readerId, metrics);
} catch (Exception e)
{
// we don't end up here
log?.Error(e, "Error in storing metrics");
}
}
} catch (Exception e)
{
// we don't end up here
log?.Warning(e, "Exception in metrics stream");
}
}
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. (Stream canceled by client.)
---> System.Exception: Stream canceled by client.
at System.Threading.Channels.AsyncOperation`1.GetResult(Int16 token)
at System.Threading.Channels.ChannelReader`1.ReadAllAsync(CancellationToken cancellationToken)+MoveNext()
at System.Threading.Channels.ChannelReader`1.ReadAllAsync(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at HarmonyBackend.Hubs.ReaderDeviceV1Hub.MetricsStream(IAsyncEnumerable`1 stream) in /builds/nedap-harmony/harmony/HarmonyBackend/Hubs/ReaderDeviceV1Hub.cs:line 224
at HarmonyBackend.Hubs.ReaderDeviceV1Hub.MetricsStream(IAsyncEnumerable`1 stream) in /builds/nedap-harmony/harmony/HarmonyBackend/Hubs/ReaderDeviceV1Hub.cs:line 224
--- End of inner exception stack trace ---