Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor Connection Disconnected

I have a web app with Client running on Blazor Server. I have set a custom Blazor reconnect modal (<div id="components-reconnect-modal"...) as the documentation says here - Microsoft Docs

Also I have these settings for SignalR and Blazor circuits:

    services.AddServerSideBlazor
        (options =>
        {
            options.DisconnectedCircuitMaxRetained = 100;
            options.DisconnectedCircuitRetentionPeriod = TimeSpan.FromMinutes(5);
            options.JSInteropDefaultCallTimeout = TimeSpan.FromMinutes(1);
            options.MaxBufferedUnacknowledgedRenderBatches = 10;
        })
        .AddHubOptions(options =>
        {
            options.ClientTimeoutInterval = TimeSpan.FromSeconds(30);
            options.EnableDetailedErrors = false;
            options.HandshakeTimeout = TimeSpan.FromSeconds(15);
            options.KeepAliveInterval = TimeSpan.FromSeconds(15);
            options.MaximumReceiveMessageSize = 32 * 1024;
            options.StreamBufferCapacity = 10;
        });

But I have an annoying problem - Whenever the app is open in a browser tab and stays still with nobody using it it disconnects. It happens very inconsistently and I can't locate the configuration for these custom time periods but I need to enlarge them. Example:

  1. Initialy loaded the app at 11:34:24AM
  2. Leave it like that for a while
  3. In the Console: "Information: Connection disconnected." at 11:55:48AM and my reconnect-modal appears.

How can I enlarge the lifetime of the connection so that it is always bigger than my session timeout. I checked the Private Memory Limit of my app pool but it is unlimited. It happens really inconsistently with the same steps to reproduce. Test 1 - 16 mins 20 sec; Test 2 - 21 mins 58 sec; Test 3 - 34 mins 56 sec...and then after iisreset...Test 4 - 6 mins 28 sec

Please help.

like image 867
Ivelin Matev Avatar asked Apr 10 '26 16:04

Ivelin Matev


1 Answers

I think that you can go around this error by using this code in _Host.cshtml:

<script>
    Blazor.start().then(() => {
        Blazor.defaultReconnectionHandler._reconnectionDisplay = {
            show: () => {},
            update: (d) => {},
            rejected: (d) => document.location.reload()
        };
    });
</script>

Please read also about Modify the reconnection handler (Blazor Server)

See also this answer

like image 109
Nb777 Avatar answered Apr 13 '26 08:04

Nb777



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!