Search code examples
asp.net-coreasp.net-core-signalr

Some issues with AspNet Core SignalR KeepAlive timeout


In our project I have set the SignalR as follow :

services.AddSignalR()
            .AddHubOptions<NotificationHub>(options =>
            {
                const int keepAliveIntervalInSeconds=60;
                options.EnableDetailedErrors=true;
                options.ClientTimeoutInterval = TimeSpan.FromSeconds(2 * keepAliveIntervalInSeconds);
                options.HandshakeTimeout = TimeSpan.FromSeconds(keepAliveIntervalInSeconds);
                options.KeepAliveInterval = TimeSpan.FromSeconds(keepAliveIntervalInSeconds);
            });

but it is not working as it supposed to do. I am getting an error in the client that says :

[2020-06-03T09:48:44.367Z] Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.

Is there anything that I am doing wrong here ?


Solution

  • Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'

    In the "Configure server options" section of this doc, we can find:

    The default value of KeepAliveInterval is 15 seconds. When changing KeepAliveInterval, we need to change the ServerTimeout/serverTimeoutInMilliseconds setting on the client side too. And the recommended ServerTimeout/serverTimeoutInMilliseconds value is double the KeepAliveInterval value.

    And the default timeout value of serverTimeoutInMilliseconds is 30,000 milliseconds (30 seconds), if you just update KeepAliveInterval setting of your SignalR hub to 60 seconds but not change the serverTimeoutInMilliseconds value on your client side, which would cause above error.