Uploading to Azure WebApp throws `ConnectionResetException: The client has disconnected`

0

I'm working on a .NET Core 3.1 webapp using C#. I use Blazor ServerSide as my front-end. The app is hosted by Azure. On my page I have an upload component. When I upload 1 file it works fine. When I upload 2-3 files it is still working but when I upload more files I get this error:

(Serilog.AspNetCore.RequestLoggingMiddleware) HTTP "POST" "/api/foo/2/bar" responded 500 in 18501.3265 ms
Microsoft.AspNetCore.Connections.ConnectionResetException: The client has disconnected
 ---> System.Runtime.InteropServices.COMException (0x800704CD): An operation was attempted on a nonexistent network connection. (0x800704CD)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Server.IIS.Core.IO.AsyncIOOperation.GetResult(Int16 token)

Most likely it has something to do with the file size of the POST. When running my webapp in Visual Studio I don't have any problems.

I also see this warning in my logging:

(Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer) Increasing the MaxRequestBodySize conflicts with the max value for IIS limit maxAllowedContentLength. HTTP requests that have a content length greater than maxAllowedContentLength will still be rejected by IIS. You can disable the limit by either removing or setting the maxAllowedContentLength value to a higher limit.

I've tried numerous options to increase the limit:

In my controller:

[Authorize]
[DisableRequestSizeLimit]
public class UploadController : BaseApiController

In Startup.cs:

            // To bypass the file limit:
            services.Configure<FormOptions>(options =>
            {
                options.ValueLengthLimit = int.MaxValue;
                options.MultipartBodyLengthLimit = long.MaxValue; // <-- !!! long.MaxValue
                options.MultipartBoundaryLengthLimit = int.MaxValue;
                options.MultipartHeadersCountLimit = int.MaxValue;
                options.MultipartHeadersLengthLimit = int.MaxValue;
            });
            services.Configure<IISServerOptions>(options =>
            {
                options.MaxRequestBodySize = null;
            });

But still no luck.

Am I missing yet another setting or is this error not related to the upload size?

c#
azure
file-upload
asp.net-core-3.1
blazor-server-side
asked on Stack Overflow Sep 24, 2020 by Paul Meems

1 Answer

0

It took me weeks to solve this together with help from Microsoft Support.
It appears the problem was only with a few clients.
I had changed the WebApp setting in Azure to use HTTP v2 instead of HTTP v1.
And it looks like in the connection from my browser to Azure one hop was dropping the HTTP v2 packages. When I reset the setting the problem went away.

answered on Stack Overflow Oct 29, 2020 by Paul Meems

User contributions licensed under CC BY-SA 3.0