2

I'm running a .NET Core SignalR Hub as a Windows Service with Kestrel under .NET Core 3.1. It is called by a Javascript SignalR Client with the newest client lib (v. 5.0.9)

Reproducible, after 20minutes the connection is stopped without any reason and reconnected after 2seconds. However, no new data is send on the new connection.

I didn't change any of the default timeout settings.

Errorlog Javascript console

public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddSignalR(hubOptions =>
            {
                hubOptions.EnableDetailedErrors = true;
                hubOptions.MaximumReceiveMessageSize = 1048576; //1MB

            }).AddJsonProtocol(options =>
            {
                options.PayloadSerializerOptions = ServiceTools.GetSerializerOptions();
                options.PayloadSerializerOptions.PropertyNameCaseInsensitive = true;
            });

        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseCors(builder => builder
                .AllowAnyHeader()
                .AllowAnyMethod()
                .SetIsOriginAllowed(_ => true)
                .AllowCredentials()
            );

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHub<VisuNotificationHub>("/signalr");
            });

          
        }
    }
pfw2.connection = new signalR.HubConnectionBuilder()
            .withUrl(signalrUrl,  ['webSockets', 'serverSentEvents', 'longPolling'])
            .configureLogging(signalR.LogLevel.Debug)
            .withAutomaticReconnect({
                nextRetryDelayInMilliseconds: retryContext => {
                    if (retryContext.elapsedMilliseconds < 10000) {             //<10sec
                        return 1000;                                            //sekündlich
                    }
                    else if (retryContext.elapsedMilliseconds < 60000) {        //<60sec/1min
                        return 10000;                                           //10-sekündlich
                    }
                    else if (retryContext.elapsedMilliseconds < 1800000) {      //<30min
                        return 300000;                                          //5-minütlich
                    }
                    else {                                                      //>= 30min
                        return 900000;                                          //15-minütlich
                    }
                }
            })
            .build();

        pfw2.connection.serverTimeoutInMilliseconds = 60000;

        //Reconnect Handler
        pfw2.connection.onreconnecting(error => {
            
            var reconnectErrorData = [{ Message: `<p style="background:red;color:white;font-size:24px">@ResOperatorDialog.ErrorPleaseRefresh</p>` }];
            console.assert(connection.state === signalR.HubConnectionState.Reconnecting);
            console.log("Error in Hub!", error);
            UpdateTicker(reconnectErrorData);
        });

        pfw2.connection.onreconnected((connectionId) => {
            onHubConnectionDone();
            console.log(connectionId);
        });

        //Closed handler
        pfw2.connection.onclose((e) => {
            var connectioNClosedErrorData = [{Message: `<p style=\"background:red;color:white\">Connection closed". Try refreshing this page to restart the connection.</p>`}];
            UpdateTicker(connectioNClosedErrorData);
            console.log(e);
        });   
       
        //connection Start
        pfw2.connection.start()
        .catch((err) => {
            return console.error(err.toString());
        })
        .then(() => {
            console.log("connected, ID=",pfw2.connection.connectionId);
            onHubConnectionDone();
        });
  • That behavior is normal for signalr. Handle multiple connection id's for each connected user inside your group. Signalr will always set the new connection id prior to release the old one. – GH DevOps Sep 08 '21 at 16:06
  • Whether you are running the application in the same client, and meet this error? Can you share the relate code about using websocket with signalR and the method about send message to client? so that we can try to reproduce the problem. Besides, you can also check if the issue is [caused by zone.js](https://stackoverflow.com/questions/59543816/signalr-asp-netcore-and-angular-websocket-is-not-in-the-open-state-disconnect). – Zhi Lv Sep 09 '21 at 03:12
  • The error exists both on the same client and on different machines. I added example code, however no "method about send message to client" as it's a problem when leaving the connection untouched for 20min, not when sending a message – DeckardCain2020 Sep 13 '21 at 12:11
  • @ZhiLv No it's not the linked zone.js problem. This refers to SignalR v.2.x, yet it is fixed in v.3.x which we are using – DeckardCain2020 Sep 13 '21 at 12:51

0 Answers0