【问题标题】:Some issues with AspNet Core SignalR KeepAlive timeoutAspNet Core SignalR KeepAlive 超时的一些问题
【发布时间】:2020-06-03 09:52:50
【问题描述】:

在我们的项目中,我将 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.'.

我在这里做错了什么吗?

【问题讨论】:

  • @sommmen 是 60 秒。你的意思是握手超时也应该大于间隔?
  • 我的错误——我读错了。我不确定 - 我没有触及这些设置,它们似乎适合我所做的任何事情。对不起。

标签: asp.net-core asp.net-core-signalr


【解决方案1】:

错误:连接因错误“错误:服务器超时而未收到来自服务器的消息而断开”。

the "Configure server options" section of this doc,我们可以找到:

KeepAliveInterval 的默认值为 15 秒。在更改KeepAliveInterval 时,我们还需要更改客户端上的ServerTimeout/serverTimeoutInMilliseconds 设置。并且推荐的ServerTimeout/serverTimeoutInMilliseconds 值是KeepAliveInterval 值的两倍。

如果您只是将 SignalR 集线器的 KeepAliveInterval 设置更新为 60 秒 但不更改 serverTimeoutInMilliseconds 值,则 serverTimeoutInMilliseconds 的默认超时值为 30,000 毫秒(30 秒)在您的客户端,这会导致上述错误。

【讨论】:

  • 事实证明,客户端设置足以满足我的想法。
猜你喜欢
  • 2020-02-27
  • 2018-02-03
  • 2018-12-13
  • 2019-02-23
  • 1970-01-01
  • 2021-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多