0

We have a net5.0 console project running a SignalR client with a net5.0 webserver hosting a SignalR server. There is no authentication required on the server. Once an hour, the client thrown an exception.

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

At that same time, the server is throwing a 404 on a POST to the SignalR Hub. Example below:

http://xxxxx/LineHub?id=NysqhPnGO1wgF5YTG1cWJw

Here is how the client connection is built:

    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();

The server configuration is as follows:

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

We do have logic to restart the connection and it does so successfully but messages to the SignalR server fail if they happen to be sent while reconnecting.

Dennis Kiesel
  • 1,902
  • 3
  • 15
  • 20
  • This error usually means that the target machine is running, but the service that you're trying to connect to is not available. (Either it stopped, crashed, or is busy with another request.). And the issue may be relates the firewall. when you meet this issue, try to check whether the client and server can ping through. Here is a [similar thread](https://stackoverflow.com/questions/5420656/unable-to-read-data-from-the-transport-connection-an-existing-connection-was-f), you could check it. – Zhi Lv May 27 '21 at 08:33
  • Communications with the SignalR server are running fine for the most part. The service is available. Messages are sent and received. Firewall ports are fine because most of the time things are working. Just once an hour there is a hiccup of some sort. The SignalR server does not go down. I can see on the server logs that it returns a 404 around the same time that the client connection is lost, as mentioned above. The link you posted was for an issue where the connection can not be made at all. That does not apply here. – Dennis Kiesel May 27 '21 at 17:43
  • Hi @DennisKiesel, have you ever solved the problem? If not, whether the hub is hosted on multiple instances without sticky sessions. Here is [an article](https://learn.microsoft.com/en-us/aspnet/core/signalr/troubleshoot?view=aspnetcore-5.0#response-code-404) about Troubleshoot connection errors, you could check it. – Zhi Lv Jun 03 '21 at 02:27
  • @ZhiLv We still have not solved the problem. We are not using multiple instances so sticky sessions are not the issue. I ran across that article when troubleshooting but it doesn't seem to apply here. – Dennis Kiesel Jun 04 '21 at 21:24

0 Answers0