Error "Could not reconnect to the server. Reload the page to restore functionality." in ASP.NET Core Blazor Server

v38armageddon ‫ 61 Reputation points
2022-11-29T20:39:30.603+00:00

Hello,

I have a ASP.NET Core Blazor Server website, self hosted in a Linux machine (Fedora) with NGINX for Cloudflare.

On my published website, after a certain moment, a error show: "Could not reconnect to the server. Reload the page to restore functionality.". When I click on "Reload", it goes back to the main page.

When my website is launched in Visual Studio 2022, the problem is not appearing.

Do you know how I can resolve this bug?

Thanks.

Developer technologies | .NET | Blazor
Developer technologies | C#
{count} vote

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 78,006 Reputation points Volunteer Moderator
    2023-08-17T15:42:41.64+00:00

    Blazor requires a persistent web socket connection. If the connection is lost, the client has about 90 seconds to reconnect. Cloudflare is aggressive on closing web socket connections, typically 100 seconds of inactivity.

    To keep the connection open you may need a "ping". Have the client run a timer and send a message to the server every 60 seconds.

    Another issue that browsers are gettin more aggressive at closing web socket connections. if the tab becomes inactive (not current visible tab), the browser may close the connection.

    Mobile devices will often lose connectivity long enough to kill a blazor server connections.

    the default reconnect logic to restart the app. you can add persistent state management, and better recovery.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.