13
votes

'Error: Server timeout elapsed without receiving a message from the server.'.

I'm trying to debug some server-side code and while I do that the client gets disconnected in less than a minute.

I'm only using SignalR to communicate to clients, without controllers yet.

Is there any setting that can disable timeout or at least make it way longer than it is now?

my launchSettings.json:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:26793",
      "sslPort": 44386
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_HTTPS_PORT": "44386"
      }
    },
    "Api": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_URLS": "https://localhost:5001;http://localhost:5000"
      }
    }
  }
}
2
Which server, IIS Express + Kestrel? That's a known issue. Try switching the launch profile to just kestrel.Tratcher
@Tratcher I edited the post and added my launchSettings.json. I think it launches Kestrel only given what the docs say: When the application is launched with dotnet run, the first profile with "commandName": "Project" will be used. The value of commandName specifies the web server to launch. commandName can be one of : IIS Express; IIS; Project (which launches Kestrel) So I guess the "Api" profile will be used with Kestrel right?Arhire Ionut
Makes sense. Reading that error again it sounds like it's coming from the SignalR client, not the server.Tratcher
@MahmoudFarahat this._hubConnection = new HubConnectionBuilder().withUrl('http://localhost:5000/match').build(); this._hubConnection.serverTimeoutInMilliseconds = 1000 * 1000; I tried to increase serverTimeoutInMilliseconds but haven't tested it beause I am very busy with other things right now. If you try it and it works please answer my post accordingly.Arhire Ionut
Yes this worked for me , I can now debug with no problem Thanks a lot 👍Mahmoud Farahat

2 Answers

12
votes

Thanks to @Arhire Ionut

Here is how to increase Javascript client timeout

hubConnection.serverTimeoutInMilliseconds = 100000; // 100 second

More details here => https://github.com/aspnet/Docs/issues/6885

11
votes

What @MahmoudFarhat mentioned in another answer is correct. 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();