5

We have developed a Blazor server application(.NET7) and hosted it. Often we are getting the below error description and we have to reload the page to make it work. frequently we are getting this issue when we are having worked on the browser tab of a blazor page and if we want to go to another tab for some other work and after comeback to the blazor page, We have been referring to some articles related to the above and we expected after .NET7 new release we can get it sorted out. However, the issue is still there and we are not able to fix the issue yet.

enter image description here

is it a SignalR connection issue or anything else, can anyone help me regarding this ??

buddhi chamalka
  • 781
  • 5
  • 23
  • This thread https://stackoverflow.com/questions/60057826/blazor-server-side-app-on-iis-frequently-disconnects-websocket-connection has various suggestions you can try. How is your service hosted? – StefanFFM Dec 01 '22 at 08:35

2 Answers2

4

I was looking into the issue myself. That's what I gathered:

  • the issue of Blazor Server reconnecting method needs improvement e.g. link link 2. There is a discussion going on GitHub and consensus is that the reconnecting mechanism needs improvement.
  • the browser tab goes to sleep and Blazor is unable to recover when a user comes back to a page due to the circuit serving the page having been deleted. Switching off power-saving mode of the web browser might help.
  • it might help to turn off power saving mode of the WiFi adapter on mobile devices.

Right now we are waiting for a fix, which I saw vaguely scheduled for .NET 8...

I have even seen a hack involving playing audio to fool heuristics of web browsers, which put a Blazor tab to sleep...

In the docs (Signal R) it suggestsed to use the Web Lock mechanism to prevent a tab going to sleep.

maciek
  • 724
  • 2
  • 4
  • 16
1

As mentioned, Blazor reconnection needs improvement (one which Microsoft seem to be pushing off - gets bumped to each new release, but then not actually implemented).

To solve the issue of the tabs going to sleep, you could add a web lock (as described on the Signal R docs):

var lockResolver;
if (navigator && navigator.locks && navigator.locks.request) {
  const promise = new Promise((res) => {
    lockResolver = res;
  });

  navigator.locks.request('unique_lock_name', { mode: "shared" }, () => {
    return promise;
  });
}

This will stop the browser putting the tab to sleep which should solve some of the issue.

aryeh
  • 610
  • 5
  • 13