You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

排查「Reading the request body timed out due to data arriving too slowly」异常诱因

Kestrel请求体读取超时异常排查与无代码修改解决方案

异常信息(中文翻译)

Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: 读取请求体超时,因为数据到达速度过慢。请查看MinRequestBodyDataRate配置。
在 Microsoft.AspNetCore.Server.Kestrel.Core.KestrelBadHttpRequestException.Throw(RequestRejectionReason reason)
在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ChunkedEncodingMessageBody.PumpAsync()
在 System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
在 System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
在 System.IO.Pipelines.Pipe.GetReadAsyncResult()
在 System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)
在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ChunkedEncodingMessageBody.ReadAsyncInternal(CancellationToken cancellationToken)
在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory1 destination, CancellationToken cancellationToken) 在 Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Memory1 buffer, CancellationToken cancellationToken)
在 Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool1 bytePool, Nullable1 limit, CancellationToken cancellationToken)
在 Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonInputFormatter.ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
在 Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.BindModelAsync(ModelBindingContext bindingContext)
在 Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)
在 Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<g__Bind|0>d.MoveNext()
--- 来自之前位置的堆栈跟踪结束 ---
在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
在 Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
在 Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
在 Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
在 Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

可能的诱因

  • 客户端侧问题
    • 网络波动:用户所在网络临时卡顿、带宽不足,导致请求体上传速率低于Kestrel的最低要求。
    • 客户端程序异常:近期客户端更新后出现逻辑错误,比如上传时暂停、分块上传逻辑故障,导致数据发送延迟或中断。
    • 大请求体传输异常:上传大文件/JSON时,客户端拆分数据的逻辑出错,部分数据块发送超时。
  • 服务端环境变化
    • Kestrel配置被误改:运维操作或部署脚本更新时,MinRequestBodyDataRate等参数被调得更严格。
    • 服务器资源紧张:CPU、内存、磁盘IO占用过高,导致Kestrel处理请求的速度变慢,间接触发读取超时。
    • 代理/中间件配置变更:前端反向代理(如Nginx、IIS)添加了限速规则,或代理本身性能瓶颈,导致请求体传输到Kestrel的速率下降。
  • 网络链路问题
    • 客户端到服务端的链路出现丢包、延迟增加:运营商网络故障、跨区域链路拥堵,导致数据传输速率不达标。

无代码修改的临时解决方案

  • 调整Kestrel配置(通过配置文件/环境变量)
    • 修改appsettings.json,放宽MinRequestBodyDataRate限制:
      "Kestrel": {
        "Limits": {
          "MinRequestBodyDataRate": {
            "BytesPerSecond": 100,
            "GracePeriod": "00:00:30"
          }
        }
      }
      
      说明:降低BytesPerSecond阈值(默认一般为240),延长GracePeriod缓冲时间。若使用IIS托管,可在web.config中调整对应设置。
    • 容器化部署场景,通过环境变量传递配置(如ASPNETCORE_Kestrel__Limits__MinRequestBodyDataRate__BytesPerSecond=100),然后滚动重启容器,避免全站停机。
  • 排查并修复资源/网络问题
    • 检查服务器CPU、内存、磁盘IO使用率,清理异常占用进程,或临时扩容资源。
    • 联系运维排查网络链路,确认是否存在丢包、延迟问题,必要时切换备用链路。
    • 恢复前端代理到之前的稳定配置,取消不必要的限速规则。
  • 针对特定请求临时绕过限制
    • 若仅特定API出现问题,可在代理层为该API单独设置更高的超时或调整缓冲区,比如Nginx中添加proxy_read_timeout 300s;。

内容的提问来源于stack exchange,提问作者CorrieJanse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 14:37:06