JulienG
JulienG

Reputation: 188

Blazor server disconnect when chrome mobile is in background

I developed a blazor server app which works fine on a desktop, and now i test her on the mobile platforms.

I met problem with the signalR connection when i put the browser in the background. When i go back, if its enough fast, i have the message "Attempting to reconnect to the server" x/8, and after it reconnect after maybe 15 seconds (which is too much), and if its like 5 minutes later im totally disconnected and i have to relaunch the app.

i found some documentation about that but nothing consistent. Because of blazor, the client configuration and event (in js) seem different than the classic signalr client, and for the server im beeing lost between the different timeout.

I try find a way to configure both server and client to manage a "sleeping" connection (ok if im disconnect after 20 minutes but i want at least be able to reconnect until 20 minutes of inactivity), but its really hard to test because im unable tu reproduce this behavior in development in my laptop.

I see some solution on internet who suggested make document.location.reload()

Blazor.defaultReconnectionHandler._reconnectCallback = function(d) {
    document.location.reload(); 

}

But its not a solution for me as i don't want to lost everything in session.

thanks for your suggestion and help !

Upvotes: 4

Views: 2320

Answers (1)

JulienG
JulienG

Reputation: 188

for those stuck into this same kind of problems, i was able to manage this by play with the signalr options described here : https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-5.0&pivots=server

actually it was not really a mobile problems because i had the same kind of behavior by putting a laptop on sleep more than 3 minutes.

The 3 minutes expiration period was coming from this parameter DisconnectedCircuitRetentionPeriod 3 minutes Maximum amount of time a disconnected circuit is held in memory before being torn down.

i just increase the time of this parameter and when the mobile/laptop go out of sleep it able to reconnect.

the blazor documentation is not really clear about that

Upvotes: 3

Related Questions