blazorblazor-server-side

Set my app server to 2 servers, getting a _blazor load error


My Blazor server app runs fine on Azure with one server. When I scale it out to two servers, I sometimes get the following. I have session affinity turned off. This clearly is the Blazor framework having problems. Any idea why?

Update: I turned on session affinity and the problem is gone. Does Blazor server require affinity so that it can have a series of system files like blazor.server.js all be read from the same server?

[2024-06-01T14:56:43.408Z] Information: Normalizing '_blazor' to 'https://louishowe-dev.azurewebsites.net/_blazor'.
blazor.server.js:1 
        
        
GET https://louishowe-dev.azurewebsites.net/_blazor?id=gc8YOVE1nE_g8k914Nk3ng&_=1717253803473 404 (Not Found)
send @ blazor.server.js:1
send @ blazor.server.js:1
send @ blazor.server.js:1
get @ blazor.server.js:1
connect @ blazor.server.js:1
_startTransport @ blazor.server.js:1
_createTransport @ blazor.server.js:1
_startInternal @ blazor.server.js:1
await in _startInternal (async)
start @ blazor.server.js:1
_startInternal @ blazor.server.js:1
_startWithStateTransitions @ blazor.server.js:1
start @ blazor.server.js:1
startConnection @ blazor.server.js:1
startCore @ blazor.server.js:1
start @ blazor.server.js:1
Pr @ blazor.server.js:1
await in Pr (async)
Ar @ blazor.server.js:1
Br @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
blazor.server.js:1 [2024-06-01T14:56:43.545Z] Error: Failed to start the transport 'LongPolling': Error: No Connection with that ID: Status code '404'
log @ blazor.server.js:1
_createTransport @ blazor.server.js:1
await in _createTransport (async)
_startInternal @ blazor.server.js:1
await in _startInternal (async)
start @ blazor.server.js:1
_startInternal @ blazor.server.js:1
_startWithStateTransitions @ blazor.server.js:1
start @ blazor.server.js:1
startConnection @ blazor.server.js:1
startCore @ blazor.server.js:1
start @ blazor.server.js:1
Pr @ blazor.server.js:1
await in Pr (async)
Ar @ blazor.server.js:1
Br @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
blazor.server.js:1 [2024-06-01T14:56:43.545Z] Error: Failed to start the connection: Error: Unable to connect to the server with any of the available transports. ServerSentEvents failed: Error: 'ServerSentEvents' does not support Binary. Error: LongPolling failed: Error: No Connection with that ID: Status code '404'
log @ blazor.server.js:1
_startInternal @ blazor.server.js:1
await in _startInternal (async)
start @ blazor.server.js:1
_startInternal @ blazor.server.js:1
_startWithStateTransitions @ blazor.server.js:1
start @ blazor.server.js:1
startConnection @ blazor.server.js:1
startCore @ blazor.server.js:1
start @ blazor.server.js:1
Pr @ blazor.server.js:1
await in Pr (async)
Ar @ blazor.server.js:1
Br @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
blazor.server.js:1 [2024-06-01T14:56:43.545Z] Error: Error: Unable to connect to the server with any of the available transports. ServerSentEvents failed: Error: 'ServerSentEvents' does not support Binary. Error: LongPolling failed: Error: No Connection with that ID: Status code '404'
log @ blazor.server.js:1
unhandledError @ blazor.server.js:1
startConnection @ blazor.server.js:1
await in startConnection (async)
startCore @ blazor.server.js:1
start @ blazor.server.js:1
Pr @ blazor.server.js:1
await in Pr (async)
Ar @ blazor.server.js:1
Br @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
(anonymous) @ blazor.server.js:1
blazor.server.js:1 [2024-06-01T14:56:43.545Z] Error: Failed to start the circuit.

Solution

  • My Blazor server app runs fine on Azure with one server. When I scale it out to two servers, I sometimes get the following. I have session affinity turned off. This clearly is the Blazor framework having problems. Any idea why?

    Well, acccording to your scenario and description the issue The issue you’re encountering is related to how Blazor Server handles SignalR connections and session state. When you scale out to multiple servers without session affinity, the client might end up connecting to a different server than the one it started the connection with. This can cause issues because Blazor Server apps rely on persistent SignalR connections.

    I turned on session affinity and the problem is gone. Does Blazor server require affinity so that it can have a series of system files like blazor.server.js all be read from the same server?

    Yes that's correct, Blazor Server applications require session affinity when scaled out to multiple servers because they maintain a stateful SignalR connection between the client and server. Without session affinity, client requests can be routed to different servers, breaking the connection and causing errors. Enabling session affinity ensures a continuous connection to the same server, resolving these issues.

    In addition, If you need to avoid session affinity for some reason (Let's say, for better load distribution), you can use a Redis backplane for SignalR. A backplane allows multiple servers to share connection state, so clients can reconnect to any server without losing their session state.

    Note: Please refer to this official document if you need more details and configuration. This document might also be insightful.