Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor server side app on IIS frequently disconnects WebSocket connection

I have a Blazor server side app published on IIS 10. When browsing to an arbitrary page and just letting it idle after a minute or so (sometimes only 45 sec, sometimes something between 1 and two minutes) the modal

Attempting to reconnect to server ...

appears for a couple of seconds. In the browser console the logging shows either

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

or

Information: Connection disconnected.

Since this seems to be a timeout problem I added the following options to ConfigureServices in my startup.cs

services.AddServerSideBlazor()
                .AddHubOptions(options =>
                {
                    options.ClientTimeoutInterval = TimeSpan.FromMinutes(10);
                    options.KeepAliveInterval = TimeSpan.FromSeconds(3);
                    options.HandshakeTimeout = TimeSpan.FromMinutes(10);
                });

This does not solve the problem though.

I also went to the advanced settings of my site in IIS and increased the connection timeout from the default 120 sec to 600 sec. This did not help either.

Those frequent disconnections only happen on the live site hosted on IIS 10. If I start the app locally with Visual Studio the connection is stable.

Any hints of what I'm missing would be appreciated!

Update:

As suggested by @agua from mars in comment below I changed transport type like this

app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapBlazorHub(options => { options.Transports = HttpTransportType.LongPolling; });
                endpoints.MapFallbackToPage("/_Host");
            });

With this change the connection is still closed. The console log shows

Information: (LongPolling transport) Poll terminated by server.

I also tried HttpTransportType.ServerSentEvents which does not work at all but gives this error

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.

Update 2:

The IIS is configured to use HTTP 1.1 I tried changing to HTTP/2 but this did not change anything regarding the disconnections.

like image 649
René Avatar asked Feb 04 '20 12:02

René


1 Answers

Try this out..

            app.UseEndpoints(endpoints =>
            {
//other settings
.
.
endpoints.MapBlazorHub(options => options.WebSockets.CloseTimeout = new TimeSpan(1, 1, 1));
//other settings
.
.
});
like image 178
Ganesh Kumbhar Avatar answered Sep 23 '22 14:09

Ganesh Kumbhar