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