Issue with Microsoft.AspNet.SignalR.Client hanging/crashing app after app being in background for 10 + minutes

37 views Asked by At

I'm encountering a problem with my ASP.NET SignalR client where, upon reopening the app after it has been in the background for around 20 minutes, the client hangs when it tries to connect. This eventually leads to either freezing the app or causing it to crash entirely.

Here's a snippet of the relevant code:

if (SignalRClient != null)
{
    await Connect(_chatGuid.ToString());
}
await SignalRClient.JoinGroup(_chatGuid.ToString(), App.entityClientGuid.ToString(), App.oSType);

which both of these methods do the following:

 public async Task Connect()
    {
        try
        {
            await _connection.Start();
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Failed to connect: {ex.Message}");
            await Reconnect();
        }
    }

public async Task JoinGroup(string roomName, string entityGuid, string deviceType)
    {
        try
        {
            await _proxy.Invoke("JoinGroup", roomName, entityGuid, deviceType);
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Failed to join: {ex.Message}");
        }
    }

I'm using Microsoft.AspNet.SignalR.Client for real-time communication in my application. It works flawlessly under normal circumstances, but the issue arises when the app has been inactive in the background for approximately 20 minutes. Upon reopening the app, the SignalR client seems to struggle to connect, causing the app to become unresponsive or crash.

I've tried debugging the issue, but I'm unable to pinpoint the exact cause. It seems like the connection process gets stuck or times out after the app has been in the background for an extended period.

Could this be related to some kind of timeout setting in SignalR or perhaps a network-related issue? Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated. Thank you!

1

There are 1 answers

2
Frank M On

Possibly related to a change in browser, specifically noted for Chrome. A websocket connection is forced closed after a period of inactivity. Comments suggest 5 - 7 minute range.

You did not note which version you are on however, this issue was fixed in v2.4.2 (although the latest at this time is v2.4.3).

https://github.com/SignalR/SignalR/issues/4536