ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response报错

2022-01-11 17:32:07  阅读:1521  来源: 互联网

标签:netty http reactor connection 报错 timeout BEFORE


后端使用的jetty服务

报错

2022-01-11 17:20:24.362  WARN 4784 --- [ctor-http-nio-3] r.netty.http.client.HttpClientConnect    : [id: 0x3eaaea4e, L:0.0.0.0/0.0.0.0:58790 ! R:localhost/127.0.0.1:8090] The connection observed an error

reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response

2022-01-11 17:20:24.362 ERROR 4784 --- [ctor-http-nio-3] a.w.r.e.AbstractErrorWebExceptionHandler : [31e53fe7-21772]  500 Server Error for HTTP GET "/status"

reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response
	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 GET "/status" [ExceptionHandlingWebHandler]
Stack trace:

说明

  • 通过网关服务Spring Cloud Gateway调用后端服务Jetty报异常

原因

  • 后端服务socket超时之后自动断开连接,网关服务从HttpClient连接池中取出了已经断开的连接进行请求

复现

  • Spring Cloud GateWay : 2.2.1.RELEASE
  • Spring Cloud : Hoxton.SR1
  • Spring Boot : 2.3.4.RELEASE
  • Server使用SpringBoot模拟

GateWay

spring:
  application:
    name: gateway
  cloud:
    gateway:
      httpclient:
        pool:
          max-idle-time: 60000ms
      routes:
      - id: dev
        uri: ${service-url.dev-service}/status
        predicates:
        - Path=/status
service-url:
  dev-service: http://localhost:8080
server:
  port: 8098

Server

spring:
  application:
    name: dev
server:
  tomcat:
    connection-timeout: 100ms

Jmeter

Threads:300
period seconds:5
Loop Count:20

说明:

  • max-idle-time:最大空闲连接时间
  • connection-timeout:socket read()超时时间。SpringBoot : server.tomcat.connection-timeout配置解析
  • GateWay的max-idle-time60000ms之后才释放连接,Server的connection-timeout100ms之后就断开连接,此时GateWay会从连接池取已经断开的连接请求,以致报错

解决

  • 因为ServerProvider, GateWayConsumer,尽可能保证Consumer先于Provider断开连接,设置max-idle-time的时间不大于connection-timeout
  • Jetty服务
    • Jetty修改jetty.http.idleTimeouthttp.timeout。默认30000ms

参考

reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response解决方案

Gateway网关使用不规范,同事加班泪两行~

【排障手记】WebClient调用抛出异常:PrematureCloseException: Connection prematurely closed BEFORE response

https://github.com/reactor/reactor-netty/pull/1442

https://github.com/reactor/reactor-netty/issues/1639

https://github.com/reactor/reactor-netty/issues/796

https://github.com/reactor/reactor-netty/issues/1092

spring-boot中内嵌jetty9配置连接超时时延

标签:netty,http,reactor,connection,报错,timeout,BEFORE
来源: https://www.cnblogs.com/wftop1/p/15789238.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有