Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot access disposed IServiceProvider on shutdown #1871

Closed
eranikid opened this issue Nov 24, 2023 · 4 comments
Closed

Cannot access disposed IServiceProvider on shutdown #1871

eranikid opened this issue Nov 24, 2023 · 4 comments

Comments

@eranikid
Copy link

eranikid commented Nov 24, 2023

Describe the bug

When being shut down, an ASP.NET Core app using Azure SignalR generates several errors:

System.ObjectDisposedException: Cannot access a disposed object. Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateScope()
   at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher`1.OnDisconnectedAsync(HubConnectionContext connection, Exception exception)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.HubOnDisconnectedAsync(HubConnectionContext connection, Exception exception)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.RunHubAsync(HubConnectionContext connection)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.OnConnectedAsync(ConnectionContext connection)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.OnConnectedAsync(ConnectionContext connection)
   at Microsoft.Azure.SignalR.ServiceConnection.ProcessApplicationTaskAsyncCore(ClientConnectionContext connection)
   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
   at System.IO.Pipelines.Pipe.GetReadAsyncResult()
   at Microsoft.Azure.SignalR.ServiceConnection.ProcessOutgoingMessagesAsync(ClientConnectionContext connection, CancellationToken token)

Error count is less than 10% of the connection count at the time of shutdown, and appears to fluctuate slightly.
These do not appear to have any negative impact, except hindering our zero-error policy.

I am not sure whether this issue lies in baseline Microsoft.AspNetCore.SignalR, or in this library, and I would be grateful if you'd help me find out and route my issue to appropriate place. I would gladly provide any additional debug information to help.

Further technical details

  • Your Azure SignalR SDK version - 1.21.7
  • ASP.NET Core 6.0
  • SignalR Client SDK is Kotlin version @ 5.0.6
@vicancy
Copy link
Member

vicancy commented Dec 5, 2023

When the application shuts down and disposes IServiceProvider, HubConnectionHandler.RunHubAsync is still running and runs into _dispatcher.OnDisconnectedAsync, even with #1876, we will see error log ErrorDispatchingHubEvent from https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/server/Core/src/HubConnectionHandler.cs#L229C12-L229C41.

Hi @BrennanConroy, do you know how aspnetcore signalr avoid such issue when shutting down the application? In theory, it could also happen when not using Azure SignalR?

@BrennanConroy
Copy link
Collaborator

It happens without ASRS as well. People haven't really complained about it though, so we haven't prioritized fixing it.

@eranikid
Copy link
Author

eranikid commented Dec 11, 2023

So the issue is in baseline Microsoft.AspNetCore.SignalR, it will be fixed someday in the future, until then our best bet is demoting the error down to warning, is that right? If so, just close the issue.

@vicancy
Copy link
Member

vicancy commented Dec 11, 2023

We fixed the error thrown from Azure SignalR SDK, but the fix for error thrown from inside the hub dispatcher depends on Microsoft.AspNetCore.SignalR. I am closing the issue here.

@vicancy vicancy closed this as completed Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants