SignalR 客户端连接关闭,同时 SignalR 服务器返回 404

时间:2021-05-26 22:25:40

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

我们有一个运行 SignalR 客户端的 net5.0 控制台项目,其中有一个托管 SignalR 服务器的 net5.0 网络服务器。服务器上不需要身份验证。每小时一次,客户端抛出异常。

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..

与此同时,服务器在向 SignalR 集线器发送 POST 时抛出 404。下面的例子:

http://xxxxx/LineHub?id=NysqhPnGO1wgF5YTG1cWJw

以下是客户端连接的构建方式:

    var connection = new HubConnectionBuilder()
        .WithUrl(lineHubUrl)
        .ConfigureLogging(s =>
        {
            s.SetMinimumLevel(LogLevel.Debug);
            s.AddFilter("Microsoft.AspNetCore.SignalR", LogLevel.Debug);
            s.AddFilter("Microsoft.AspNetCore.Http.Connections", LogLevel.Debug);
            s.AddApplicationInsights(configuration.GetValue<string>("ApplicationInsights:InstrumentationKey"));
        })
        .WithAutomaticReconnect(new RandomRetryPolicy())
        .Build();

服务器配置如下:

    services.AddSignalR(options =>
    {
        options.MaximumReceiveMessageSize = null;
        options.EnableDetailedErrors = true;
        options.ClientTimeoutInterval = TimeSpan.FromMinutes(1);
        options.HandshakeTimeout = TimeSpan.FromMinutes(1);
    });

我们确实有重新启动连接的逻辑并且它成功了,但是如果在重新连接时碰巧发送到 SignalR 服务器的消息会失败。

0 个答案:

没有答案