Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - Change server timeout response

i've created a SignalR application but when i set the KeepAliveInternal and ClientTimeOutInterval a value in the hub configuration, the application ignore it and always set to "30,000ms" for both. This is my code:

 public void ConfigureServices(IServiceCollection services)
 {
     services.AddRazorPages();
     services.AddSignalR().AddHubOptions<ActivityHub>(SetConfig);

     // Local function to set hub configuration
     void SetConfig(HubOptions<ActivityHub> options)
     {
         options.ClientTimeoutInterval = TimeSpan.FromMinutes(30);
         options.KeepAliveInterval = TimeSpan.FromMinutes(15);
     }
}

I've read the SignalR Net Core docs and there is no limit for these two properties. The timeout always is "30,000" even i set those to differente values.

like image 859
Dylan Avatar asked Jan 03 '20 22:01

Dylan


People also ask

How do I set SignalR connection timeout?

Timeout configuration for SignalR can be set in Application_Start method of Global class in Global. asax. cs file. // Wait a maximum of 30 minutes after a transport connection is lost // before raising the Disconnected event to terminate the SignalR connection.

How long do SignalR connections stay open?

The default keepalive timeout period is currently 20 seconds. If your client code tries to call a Hub method while SignalR is in reconnecting mode, SignalR will try to send the command. Most of the time, such attempts will fail, but in some circumstances they might succeed.

Is SignalR long polling?

SignalR is a Microsoft framework specifically designed to facilitate real-time client/server communication. It provides an effective implementation of long polling that doesn't have a deep impact on the server, and at the same time ensures that clients are appropriately updated about what's going on remotely.


Video Answer


1 Answers

when i set the KeepAliveInternal and ClientTimeOutInterval a value in the hub configuration, the application ignore it and always set to "30,000ms" for both.

For SignalR JavaScript client, the default serverTimeoutInMilliseconds value is 30,000 milliseconds (30 seconds). If you set KeepAliveInterval of HubOptions with a value > 30 seconds, but not specify an appropriate value for serverTimeoutInMilliseconds of HubConnection on client side, the connection will be terminated with an error, like below.

enter image description here

To fix it, you can try to set serverTimeoutInMilliseconds of your HubConnection, like below.

var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub")
    .configureLogging(signalR.LogLevel.Trace)
    .build();

connection.serverTimeoutInMilliseconds = 120000;

Test Result

enter image description here

Note:

In my above test, I configure SignalR hubs with below code snippet, and we can find a ping message is sent automatically per 60s.

hubOptions.ClientTimeoutInterval = TimeSpan.FromMinutes(2);
hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(1);
like image 192
Fei Han Avatar answered Nov 05 '22 08:11

Fei Han