1

I tried to apply some of these settings. Some work, some don't.

//_Layout.cshtml
@using Microsoft.AspNetCore.Components.Web
@namespace BlazorApp1.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <base href="~/" />
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
    <link href="css/site.css" rel="stylesheet" />
    <link href="BlazorApp1.styles.css" rel="stylesheet" />
    <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
    @RenderBody()

    <div id="blazor-error-ui">
        <environment include="Staging,Production">
            An error has occurred. This application may no longer respond until reloaded.
        </environment>
        <environment include="Development">
            An unhandled exception has occurred. See browser dev tools for details.
        </environment>
        <a href="" class="reload">Reload</a>
        <a class="dismiss"></a>
    </div>

    <environment include="Development">
        <script src="_framework/blazor.server.js" autostart="false"></script>
        <script>
            document.addEventListener("DOMContentLoaded", function () {
                Blazor.start({
                    configureSignalR: function (builder) {
                        let c = builder.build();
                        c.serverTimeoutInMilliseconds = 5000;
                        c.keepAliveIntervalInMilliseconds = 2500;
                        builder.build = () => {
                            return c;
                        };
                    },
                    reconnectionOptions: {
                        retryIntervalMilliseconds: 500,
                        maxRetries: 25
                    }
                });
            });
        </script>
    </environment>
    <environment exclude="Development">
        <script src="_framework/blazor.server.js"></script>
    </environment>
</body>
</html>

[above Code edited to reflect comment.]

Note: the important part is the 2nd script tag, which follows <script src="_framework/blazor.server.js" autostart="false"></script>. Also note, that in this variation I use the DOMContentLoaded event, but some examples simply omit this and only use Blazor.start(...), which IMHO both are valid, and I did not notice any difference so far.

Sidenote: Some sources say that the JS for Starting Blazor should/can be placed in _Host.cshtml. I assume from the project structure, that both styles are valid options. (_Host.cshtml is simply the @RenderBody and holds the App-component, which should result in roughly the same final DOM).

and

//program.cs
builder.Services.AddServerSideBlazor(options =>
{
    options.DetailedErrors = true;
}).AddHubOptions(options =>
{
    options.ClientTimeoutInterval = TimeSpan.FromSeconds(30);
    options.EnableDetailedErrors = true;
    options.HandshakeTimeout = TimeSpan.FromSeconds(15);
    options.KeepAliveInterval = TimeSpan.FromSeconds(1);
    //options.MaximumParallelInvocationsPerClient = 1;
    //options.MaximumReceiveMessageSize = 32 * 1024;
    //options.StreamBufferCapacity = 10;
});

Test when clicking "PAUSE" in VS Debug-Mode:

When I pause the App in VS, the reconnect UI shows:

Attempting to reconnect to the server: 6 of 35

But each attempt takes over 1:30 minutes (not always the same time)!

Another Test showed: one attempt ~40sec another over ~90sec.

Another Test showed: the first few (5) took a longer time but then for the remaining it was ~7sec consistently.

Specifically maxRetries: 35 works as expected every time, but it seems to me retryIntervalMilliseconds: 1000 does not work at all.

Why is that, what can I do that each attempt takes the same time, and how can I reliably set it up? Maybe a working example?

Specifically, I'd like to have a setup where each attempt really runs quickly (<1000ms) and a lot of them.

Are there some min values maybe, if so, where is the documentation on that?

[Edit]:

I ran more tests with a remote PC: With very different results for the time taken of each attempt, depending on how the connection is disturbed.

  • Firewall (all always 20s)
  • Wi-Fi (first one 10s then 0.5s)
  • Browser offline mode (all always 0.5s)
  • VS Pause / Stop (inconsistent ~40s, ~90s)

Console Output: Console Output:

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
somedotnetguy
  • 557
  • 2
  • 14
  • 1
    The retryIntervalMilliseconds is how long the client waits after failing to connect. What's taking 40 seconds or 90 seconds is the actual connection attempt which isn't affected by the retryIntervalMilliseconds setting. – Brennan Jan 18 '23 at 22:34
  • The script you have shared I can see you are missing this important part [``](https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-7.0#adjust-the-reconnection-retry-count-and-interval-blazor-server). Not sure if you are missing this reference on your real code. Please link it and try again. In addition, are you getting any eror on your console? – Md Farid Uddin Kiron Jan 19 '23 at 07:45
  • @MdFaridUddinKiron No, I was not missing that script, I simply omitted it on SO, since I assumed it belonged to the standard template. However I updated the question with the full code of the _Layout.cshtml for clarity. – somedotnetguy Jan 19 '23 at 12:04
  • @Brennan this sounds reasonable. Do you have any insight, on how long the time for the *actual attempt* takes, and why. For example Browser offline mode or WiFi off seems to result in the *actual attempt* being immediately stopped (which let me only notice the interval) but Pausing VS (90s wait) and Firewall on server blocking (20s) all have different timings. Are there some mechanism that return immediate failure of attempt vs some that leave it undefined / for some timeout to run out ? – somedotnetguy Jan 19 '23 at 12:12

0 Answers0