Skip to content

Blazor server-side: Accumulated SignalR messages hits IIS 30Mb limit #13470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tewr opened this issue Aug 27, 2019 · 4 comments
Closed

Blazor server-side: Accumulated SignalR messages hits IIS 30Mb limit #13470

Tewr opened this issue Aug 27, 2019 · 4 comments
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Comments

@Tewr
Copy link

Tewr commented Aug 27, 2019

Describe the bug

When using Server-side blazor and IIS hosting, the IIS 30Mb upload limit is reached after a certain amount of interop messages (I'd guess, around 30Mb :P)

This problem is limited to the use of WebSockets under IIS, if SignalR fallbacks to XHR, there is no problem.

To Reproduce

Steps to reproduce the behavior:

  1. Using 3.0.100-preview8-013656 / VS 19 16.3 Preview 2
  2. Create a new Blazor server-side project.
    Paste the following code in index.razor:
@page "/"
@inject IJSRuntime js
<h1>IIS "Request body too large" reproduction</h1>

<button @onclick="IISProblem">Click here to launch the test</button>
<pre>@output</pre>

@code {
    string output = "";
    public async Task IISProblem()
    {
        // Create a js method that echoes data
        await js.InvokeAsync<string>("eval", "window.t = function(s) { return s ; }");

        output += $"Creating big string...{Environment.NewLine}";
        this.StateHasChanged();
        // Create a string that passes the defsault signalR limit
        var data = "ABCDEGFHIJKLMNOPQRSTUVXYZ";
        var largeString = data;
        while (System.Text.ASCIIEncoding.ASCII.GetByteCount(largeString + data) < 30768)
        {
            largeString += data;
        }

        output += $"Transferring ({System.Text.ASCIIEncoding.ASCII.GetByteCount(largeString)} bytes) string back and forth...{Environment.NewLine}";
        this.StateHasChanged();

        var bugAppearsAtLeastAt = (40 * 1024 * 1024);
        for (var i = 0; i < (bugAppearsAtLeastAt / 30768) ; i++)
        {
            var p = await js.InvokeAsync<string>("t", largeString);
            var x = p;
        }

        output += $"Success! bug not reproduced!";
    }
}
  1. Launch using default config (IIS Express), click the button
  2. See error:
Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer: Error: Unexpected exception in "IISHttpContext.ReadBody".

Microsoft.AspNetCore.Server.IIS.BadHttpRequestException: Request body too large.
   at Microsoft.AspNetCore.Server.IIS.BadHttpRequestException.Throw(RequestRejectionReason reason)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadBody()
Microsoft.AspNetCore.SignalR.HubConnectionHandler: Error: Error when processing requests.

System.IO.InvalidDataException: Connection terminated while reading a message.
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.DispatchMessagesAsync(HubConnectionContext connection)
   at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.RunHubAsync(HubConnectionContext connection)
Microsoft.AspNetCore.Routing.EndpointMiddleware: Information: Executed endpoint '/_blazor'

Expected behavior

The text "Success! bug not reproduced!" appears.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

The problem can also be reproduced with IIS (rather than IIS express).

I have not been able to work around this using the following in web.config:

<system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="1048576000" />
        </requestFiltering>

Workarounds

  1. If the following is added to Startup.cs, it avoids the problem:
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.Use(async (context, next) =>
            {
                context.Features.Get<IHttpMaxRequestBodySizeFeature>()
                    .MaxRequestBodySize = null; // setting this to a number will just postpone the bug until that limit has reached (i.e 50Mb will still break after three pushes of the button in the example above)

                await next.Invoke();
            });
  1. Use Kestrel - OK
  2. Use IIS Without websockets (Falls back to XHR) - OK

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise>dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview8-013656
Commit: 8bf06ffc8d

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\

Host (useful for support):
Version: 3.0.0-preview8-28405-07
Commit: d01b2fb7bc

.NET Core SDKs installed:
1.1.13 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009497 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
2.2.102 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.0.100-preview-009812 [C:\Program Files\dotnet\sdk]
3.0.100-preview-010184 [C:\Program Files\dotnet\sdk]
3.0.100-preview8-013656 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview-18579-0056 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview-19075-0444 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview8.19405.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview-27122-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview-27324-5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-alpha-27128-4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.0-preview-27325-3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Aug 27, 2019
@BrennanConroy BrennanConroy added area-servers and removed area-blazor Includes: Blazor, Razor Components labels Aug 27, 2019
@BrennanConroy
Copy link
Member

@jkotalik @Tratcher Looks like a regression in 3.0 caused by #9475 where upgraded requests have the max request limit applied to them when it shouldn't.

@Pilchie This effectively makes WebSockets with IIS useless, we should definitely fix it for 3.0.

@Pilchie
Copy link
Member

Pilchie commented Aug 27, 2019

@BrennanConroy is there a PR with the fix I can take to Tactics this morning? It's likely too late for Preview 9, but target release/3.0?

@BrennanConroy
Copy link
Member

I've started a PR at #13477

Currently testing it locally and with Helix. The fix is commented out in the PR right now.

@BrennanConroy
Copy link
Member

Thanks for the report @Tewr!

This will be fixed in 3.0.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

No branches or pull requests

5 participants