Azure / azure-signalr

Azure SignalR Service SDK for .NET
https://aka.ms/signalr-service
MIT License
423 stars 100 forks source link

How do I handle the exception - 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. #1928

Open marafiq opened 5 months ago

marafiq commented 5 months ago

Describe the bug

Getting the below exception when sending message to client using Groups.
How do I avoid this or gracefully handle this? Like below

public static void Notify(long Id, params string[] keys)
  {
      GetHubContext<CountsHub>()
          .Clients
          .Group(GroupKey.FormatWith(Id))
          .notify(GetCounts(Id, default, keys));
  }

Exceptions (if any)

System.InvalidOperationException: No service connection found when sending message
  File "AzureTransport.cs", line 106, in Task AzureTransport.Send(object value)
    throw new InvalidOperationException("No service connection found when sending message");
  File "/_/src/Microsoft.AspNet.SignalR.Core/Hubs/HubDispatcher.cs", line 235, col 21, in Task HubDispatcher.InvokeHubPipeline(IHub hub, IJsonValue[] parameterValues, MethodDescriptor methodDescriptor, HubRequest hubRequest, StateChangeTracker tracker)+(Task<object> task) => { } [1]
  File "/_/src/Microsoft.AspNet.SignalR.Core/TaskAsyncHelper.cs", line 1006, col 17, in TResult TaskAsyncHelper.RunWithPreservedCulture<T1, T2, TResult>(CulturePair preservedCulture, Func<T1, T2, TResult> func, T1 arg1, T2 arg2)
  File "/_/src/Microsoft.AspNet.SignalR.Core/TaskAsyncHelper.cs", line 1017, col 13, in TResult TaskAsyncHelper.RunWithPreservedCulture<T, TResult>(CulturePair preservedCulture, Func<T, TResult> func, T arg)
  File "/_/src/Microsoft.AspNet.SignalR.Core/TaskAsyncHelper.cs", line 1071, col 43, in Task TaskAsyncHelper.ContinueWithPreservedCulture(Task task, Action<Task> continuationAction, TaskContinuationOptions continuationOptions)+(Task<T> t) => { }
  ?, in void ContinuationResultTaskFromResultTask<TAntecedentResult, TResult>.InnerInvoke()
  ?, in void Task.Execute()

Further technical details

vicancy commented 4 months ago

Need to fix, currently the code throws at https://github.com/Azure/azure-signalr/blob/89f393086b829b0fe8426aaf6ad4b664c6aff5fc/src/Microsoft.Azure.SignalR.AspNet/Transports/AzureTransport.cs#L115