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.
Steps to reproduce the behavior:
@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!";
}
}
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'
The text "Success! bug not reproduced!" appears.
If applicable, add screenshots to help explain your problem.
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>
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();
});
2) Use Kestrel - OK
3) 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]
@jkotalik @Tratcher Looks like a regression in 3.0 caused by https://github.com/aspnet/AspNetCore/pull/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.
@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?
I've started a PR at https://github.com/aspnet/AspNetCore/pull/13477
Currently testing it locally and with Helix. The fix is commented out in the PR right now.
Thanks for the report @Tewr!
This will be fixed in 3.0.
Most helpful comment
Thanks for the report @Tewr!
This will be fixed in 3.0.