Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR connection timeouts if browser tab is inactive

If I keep browser tab active (open it at least once per 5-6 mins) my WebSocket connection keeps alive through ping requests (see attached screenshot). But if I abandon the tab for 10 minutes or so, /ping requests stop happening and WebSocket connection terminates. Any explanation for this and how can it be bypassed to keep connection alive while device is awake?

PS: I suspect that our recent migration to Azure Web services could be related. Or some browser policies could change. Having SignalR implemented for a few years we now experience such issues for the first time.

enter image description here

like image 561
Maksim Ramanovich Avatar asked Feb 22 '21 21:02

Maksim Ramanovich


People also ask

What causes SignalR to disconnect?

If a server does not become available within the disconnect timeout period, the SignalR connection ends. In this scenario, the Closed event ( disconnected in JavaScript clients) is raised on the client but OnDisconnected is never called on the server.

How do I set SignalR connection timeout?

Configuration. ConnectionTimeout = TimeSpan. FromSeconds(40); // Wait a maximum of 30 seconds after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection.

How do I stop SignalR connection?

hub. stop(). done(function() { alert('stopped'); });

How many connections SignalR can handle?

In the default mode, the app server creates five server connections with Azure SignalR Service. The app server uses the Azure SignalR Service SDK by default. In the following performance test results, server connections are increased to 15 (or more for broadcasting and sending a message to a big group).


1 Answers

We were able to mitigate the issue by increasing disconnect timeout to 90s and setting keep alive property to 10s on the server (ASP.NET app).

GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(90);
GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);

But I'm still waiting for an official response on Github.

like image 129
Maksim Ramanovich Avatar answered Oct 19 '22 00:10

Maksim Ramanovich