Azure / azure-signalr

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

v1.26.0 spamming with "OnDisconnectedAsync" error #1988

Open DevVanilli opened 1 month ago

DevVanilli commented 1 month ago

With a recent version update, the library started spamming with the given error. It happens whenever application is stopped/restarted.

Error when dispatching '"OnDisconnectedAsync"' on hub. System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it (or one of its parent scopes) has already been disposed. at Autofac.Core.Lifetime.LifetimeScope.ThrowDisposedException() at Autofac.Core.Lifetime.LifetimeScope.BeginLifetimeScope(Object tag) at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher1.OnDisconnectedAsync(HubConnectionContext connection, Exception exception) at Microsoft.AspNetCore.SignalR.HubConnectionHandler1.HubOnDisconnectedAsync(HubConnectionContext connection, Exception exception) at Microsoft.AspNetCore.SignalR.HubConnectionHandler1.RunHubAsync(HubConnectionContext connection) at Microsoft.AspNetCore.SignalR.HubConnectionHandler1.OnConnectedAsync(ConnectionContext connection) at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.OnConnectedAsync(ConnectionContext connection) at Microsoft.Azure.SignalR.ServiceConnection.ProcessApplicationTaskAsyncCore(ClientConnectionContext connection)

vwxyzh commented 1 month ago

@vicancy, it looks related with #1960 DefaultHubDispatcher --> HubLifetimeManager\ ServiceLifetimeManager\ : ServiceLifetimeManagerBase\ : HubLifetimeManager\ ServiceLifetimeManager\ --> IServiceConnectionManager\ ServiceConnectionManager\ : IDisposable, IServiceConnectionManager\

DevVanilli commented 1 month ago

Interesting. Supposedly v1.26.0 fixed the problem but for me the problem started with that version (maybe just a coincidence).

vicancy commented 1 month ago

Connections were not cleaned up when disposing server connections. So it is possible that the HubDispatcher is running when the server connection is disposed. Maybe v1.26 further exposed the issue.

vicancy commented 3 weeks ago

It's interesting that v1.26 introduce in the error, the error should be always there. Hi @DevVanilli , is it possible for you to share with me a mini-project that could repro the issue that uses Autofac?

dstj commented 1 week ago

@vicancy

Are you saying this should be fixed? Because after upgrading from Microsoft.Azure.SignalR" Version="1.26.0" to Microsoft.Azure.SignalR" Version="1.26.1", I see this error many, many times every time I deploy a new version of my app on Azure (Docker container):

HResult -2146232798
Message Cannot access a disposed object.Object name: 'IServiceProvider'.
ObjectName IServiceProvider
Source Microsoft.Extensions.DependencyInjection
StackTrace at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
  at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.OnDisconnectedAsync(HubConnectionContext connection, Exception exception)
  at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.HubOnDisconnectedAsync(HubConnectionContext connection, Exception exception)
TargetSite Void ThrowObjectDisposedException()
Type System.ObjectDisposedException