11
votes

I'm trying out the latest SignalR on ASP.NET Core 2.1. I have the basic app working but it times out pretty soon right now. I see this error -

Error: Connection disconnected with error 'Error: Server timeout elapsed without receiving a message from the server.'.

Where can this timeout setting be changed? I tried the docs here but no info about timeout there. I'm running on a dev environment of Windows 10 and using JavaScript client.

Edit: Inserting image after enabling client logging.

enter image description here

Edit 2: Link to page containing timeouts about the older SignalR version.

2
I would turn on client logging first to see why you aren't getting keep alive messages,davidfowl
@davidfowl I've included the screenshot after enabling logging. I let the connection be idle without using the app for few secondsuser3165209
@davidfowl I've increased the KeepAliveInterval in my Startup but couldn't increase ServerTimeout - could this be due to this setting?user3165209
Yes that's exactly the reason... Why did you increase the keep alive setting?davidfowl
@MahmoudFarahat this worked for me. I'll select the answer in that link. This question will now be a duplicate but the answer was updated last week so I couldn't find this initially.user3165209

2 Answers

13
votes

For people that may come here in future:

Here is how to increase Javascript client timeout

hubConnection.serverTimeoutInMilliseconds = 100000; // 100 second

But also take a look at this link and then read my comments below:

If signalR got disconnected, you should try re-establishing the connection again. The connection could drop for several other reasons, including the user switching networks. For example if the user is using a cell-phone and connected to the home/office wifi but steps out which then connects to cellular data connection.

To reconnect you could use the following (works like a charm for me):

// re-establish the connection if connection dropped
connection.onclose(() => setTimeout(startSignalRConnection(connection), 5000));

where startSignalRConnection is :

const startSignalRConnection = connection => connection.start()
  .then(() => console.info('Websocket Connection Established'))
  .catch(err => console.error('SignalR Connection Error: ', err));

and connection is

const connection = new HubConnectionBuilder()
  .withUrl(connectionHub, options)
  .withHubProtocol(protocol)
  .build();
2
votes

in startup.cs

services.AddSignalR(hubOptions =>
            {
                hubOptions.EnableDetailedErrors = true;
                hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(60);
            })