Azure / azure-signalr

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

Aspnet SignalR server connection not disposed when app shuts down #1959

Closed bjqian closed 4 months ago

bjqian commented 4 months ago

Describe the bug

When the web app shuts down, due to the adhoc configured here : All the componets that are injected into the default resolver will be disposed. But the server connections are managed by serviceManager which doesn't dispose them :https://github.com/Azure/azure-signalr/blob/53f7d05d28bfb22cd46e5a39a558f6734800a1f9/src/Microsoft.Azure.SignalR.AspNet/ServerConnections/ServiceConnectionManager.cs#L136

To Reproduce

In the example: https://github.com/Azure/azure-signalr/blob/53f7d05d28bfb22cd46e5a39a558f6734800a1f9/samples/AspNet.ChatSample/AspNet.ChatSample.SelfHostServer/Program.cs#L9 add a delay after the using of WebApp.Start. Press enter in cmd line to trigger dispose. Then the app server will get intp a stucking mode: The server connection is still alive but it will throw exception like "Cannot access a disposed object.Object name: 'LoggerFactory'.""}. when client connect event is triggered. image

bjqian commented 4 months ago

The fix is included in Release 1.26: https://github.com/Azure/azure-signalr/releases/tag/v1.26.0