I'm using SignalR for communication between a Vue.js frontend and dotnet backend.
When you background the frontend tab after a (seemingly random) amount of time the connection gets disconnected. Because I'm using auto reconnect the socket is then reconnected, but then until the tab is re-focused the socket will continue to get disconnected every couple of minutes putting it in a reconnecting loop.
A few things:
Client side code is extremely basic:
this.connection = new HubConnectionBuilder()
.withUrl(this.url)
.withAutomaticReconnect()
.build()
Server side code is similarly basic:
public override async Task OnConnectedAsync()
{
//Create client code here
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
if(exception != null) _logger.LogErrorToFile(exception.Message);
_logger.LogInformationToFile($"Client with id: {GetConnectionId()} disconnected.{GetUsername()}");
await base.OnDisconnectedAsync(exception);
}
Chrome made an update earlier this year that stops connections when they are not in focus after about 5 minutes. The issue/fix that Nirbhay commented is actually for the ASP.NET version (2.4.2) and not compatible with .NET CORE. Here is the issue that was raised for .NET CORE - github.com/dotnet/aspnetcore/issues/31079