c# - 上传到 Azure WebApp 会引发“ConnectionResetException:客户端已断开连接”
问题描述
我正在使用 C# 开发 .NET Core 3.1 webapp。我使用 Blazor ServerSide 作为我的前端。该应用程序由 Azure 托管。在我的页面上,我有一个上传组件。当我上传 1 个文件时,它工作正常。当我上传 2-3 个文件时它仍在工作,但是当我上传更多文件时,我收到此错误:
(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)
很可能它与 POST 的文件大小有关。在 Visual Studio 中运行我的 webapp 时,我没有任何问题。
我还在日志中看到了这个警告:
(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.
我尝试了许多选项来增加限制:
在我的控制器中:
[Authorize]
[DisableRequestSizeLimit]
public class UploadController : BaseApiController
在 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;
});
但仍然没有运气。
我是否缺少另一个设置,或者此错误与上传大小无关?
解决方案
在 Microsoft 支持的帮助下,我花了数周时间解决了这个问题。
看来问题只出在少数客户身上。
我已将 Azure 中的 WebApp 设置更改为使用 HTTP v2 而不是 HTTP v1。
看起来在从我的浏览器到 Azure 的连接中,一跳就丢弃了 HTTP v2 包。当我重置设置时,问题就消失了。
推荐阅读
- asp.net - AWS RDS 的间歇性 SQL 连接问题
- django - 哪些表、触发器、视图受 PostgreSQL 中的删除列级联影响
- angular - Angular LoadingService 策略引发表达式更改错误
- javascript - React Native post请求在显示数组时导致无限循环
- embedded-linux - 我如何将 uClibc 用于 C 库?系统初始化的busybox?和我的 Yocto Linux 映像的 Thumb-2 说明
- maven - 如何使用 infinispan 依赖解决 ivy 中的依赖问题?
- excel - 当用户单击用户窗体上的 X 按钮时如何退出循环?
- php - 如何使用 oauth 2.0 为其他人提供使用我的服务登录的便利
- javascript - 在Angular + Nativescript中将项目添加到数据库时刷新列表视图项目
- java - jOOQ - 重用 SelectConditionStep