AspNet Core SignalR KeepAlive 超时的一些问题
Some issues with AspNet Core SignalR KeepAlive timeout
在我们的项目中,我将 SignalR 设置如下:
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);
});
但它没有按预期工作。我在客户端中收到一条错误消息:
[2020-06-03T09:48:44.367Z] Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.
我这里有什么地方做错了吗?
Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'
在the "Configure server options" section of this doc中,我们可以找到:
KeepAliveInterval
的默认值为15秒。更改 KeepAliveInterval
时,我们也需要在客户端 更改 ServerTimeout/serverTimeoutInMilliseconds
设置 。推荐的 ServerTimeout/serverTimeoutInMilliseconds
值是 KeepAliveInterval
值的两倍。
并且 serverTimeoutInMilliseconds 的默认超时值为 30,000 毫秒(30 秒),如果您只是将 SignalR 集线器的 KeepAliveInterval
设置更新为 60 秒 但不要更改客户端的 serverTimeoutInMilliseconds
值,这会导致上述错误。
在我们的项目中,我将 SignalR 设置如下:
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);
});
但它没有按预期工作。我在客户端中收到一条错误消息:
[2020-06-03T09:48:44.367Z] Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.
我这里有什么地方做错了吗?
Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'
在the "Configure server options" section of this doc中,我们可以找到:
KeepAliveInterval
的默认值为15秒。更改 KeepAliveInterval
时,我们也需要在客户端 更改 ServerTimeout/serverTimeoutInMilliseconds
设置 。推荐的 ServerTimeout/serverTimeoutInMilliseconds
值是 KeepAliveInterval
值的两倍。
并且 serverTimeoutInMilliseconds 的默认超时值为 30,000 毫秒(30 秒),如果您只是将 SignalR 集线器的 KeepAliveInterval
设置更新为 60 秒 但不要更改客户端的 serverTimeoutInMilliseconds
值,这会导致上述错误。