3

If I debug my code for more than 30 seconds, the web page shows

"Attempting to reconnect to the server: # of 8"

and dev console message is

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

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

Amir Charkhi
  • 768
  • 7
  • 23
joke labs
  • 31
  • 1
  • 2
  • Why is it a problem? Can you not just let it disconnect, all the while you're fixing your code, then reconnect it later when the server will respond to SignalR pings again? – Caius Jard Aug 12 '21 at 05:36
  • Reply to comment: NO NO NO!!! This problem is on every "BREAK" this means, exceptions, but also BREAKPOINTS. Sometimes you want to stay at a breakpoint for more than 30secs and think about it and then continue! (maybe there's nothing to fix, or you need to analyze to find out what, hence debugging with breakpoints) But continuing debugging the C# code, while the UI is already disconnected, still works, but is ofc not as useful. – somedotnetguy Jan 17 '23 at 11:25

3 Answers3

3

In case you use long polling you need to add also this configuration option:

app.UseEndpoints(endpoints =>
    // other settings go here
    endpoints.MapBlazorHub(options => {
        options.WebSockets.CloseTimeout = new TimeSpan(1, 1, 1);
        options.LongPolling.PollTimeout = new TimeSpan(1, 0, 0);
    })
);
Nicola Biada
  • 2,325
  • 1
  • 8
  • 22
1

Modify the _Host.cshtml file (or _Layout.cshtml in ASP.NET 6):

<environment include="Development">
  <script src="_framework/blazor.server.js" autostart="false"></script>
  <script>
    Blazor.start({
      configureSignalR: function (builder)
      {
        let c = builder.build();
        c.serverTimeoutInMilliseconds = 9999999;
        builder.build = () => c;
      }});
  </script>
</environment>
<environment exclude="Development">
  <script src="_framework/blazor.server.js"></script>
</environment>
palota
  • 465
  • 4
  • 8
  • interesting solution to configure form JS. is there any documentation on that, for all options ect. what is possible there? – somedotnetguy Jan 17 '23 at 11:27
  • @somedotnetguy There is [documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-7.0#configure-signalr-timeouts-and-keep-alive-on-the-client) – palota Feb 15 '23 at 08:19
  • Blazor Server - the file you need to modify is _Host.cshtml (not _Layout.cshtml) – panpawel Jun 13 '23 at 19:44
0

Try adding this in your Startup.cs or Program.cs, whichever one you're using and set then TimeSpan to your desired timeout length:

app.UseEndpoints(endpoints =>
    // other settings go here
    endpoints.MapBlazorHub(options => options.WebSockets.CloseTimeout = new TimeSpan(1, 1, 1));
});
faso
  • 679
  • 7
  • 25