首页 > 解决方案 > Spring Cloud Gateway:发布大文件时出现“连接已在响应之前关闭,同时发送请求正文”错误

问题描述

我在 spring 云网关后面运行了 spring boot 应用程序。

春季启动应用程序控制器:

@PostMapping(value = "hi")
public String postHi(@RequestHeader HttpHeaders headers, HttpServletRequest request) {
  return request.getHeader("Content-Length");
}

Spring Cloud 网关路由配置:

spring:
  cloud:
    gateway:
      routes:
        - id: hi
          uri: http://localhost:8080/hi
          predicates:
            - Path=/hi/**

因此,当我通过邮递员请求上传小文件(大小:1000 KB)时,我没有收到任何错误,但是当文件很大(大小:10 MO)时,我收到以下错误:

{
    "timestamp": "2019-12-10T20:52:33.554+0000",
    "path": "/hi",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Connection has been closed BEFORE response, while sending request body",
    "requestId": "ad589017"
}

使用此堆栈:

reactor.netty.http.client.PrematureCloseException: Connection has been closed BEFORE response, while sending request body
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
    |_ checkpoint ⇢ HTTP POST "/hi" [ExceptionHandlingWebHandler]
Stack trace:

这是重现该问题的示例: https ://github.com/jemmali-git/examples.git

标签: javaspring-bootspring-cloud-gatewayreactor-netty

解决方案


推荐阅读