一 问题描述:
环境版本:
# Spring Boot版本
springBootVersion=2.3.1.RELEASE
# Spring Cloud版本
springCloudVersion=Hoxton.SR6
SpringCloudGateway网关运行一段时间之后,服务无端端挂掉了,但是jps查进程是还在的,然后通过查看日志发现了不断在报一个WARN如下:
io.netty.channel.unix.Errors$NativeIoException: accept(..) failed: 打开的文件过多 2020-10-12 09:49:33.132 WARN 25838 --- [or-http-epoll-1] io.netty.channel.DefaultChannelPipeline : An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception. # 或者英文错误: io.netty.channel.unix.Errors$NativeIoException: accept(..) failed: Too many open files
二 问题原因:
通过查看github上spring-cloud-gateway issue找到了对应的问题的原因,并且级联找到对应的问题根源所在的reactor-netty和spring-boot上报出来的issues如下:
https://github.com/reactor/reactor-netty/issues/1152
https://github.com/spring-projects/spring-boot/issues/21923
真正的原因是:reactor-natty:0.9.8.RELEASE 存在描述符泄漏问题
我们查看一下依赖
+--- org.springframework.cloud:spring-cloud-starter-gateway -> 2.2.3.RELEASE | \--- org.springframework.boot:spring-boot-starter-webflux:2.3.0.RELEASE -> 2.3.1.RELEASE | +--- org.springframework.boot:spring-boot-starter-reactor-netty:2.3.1.RELEASE | | \--- io.projectreactor.netty:reactor-netty -> 0.9.8.RELEASE
依赖中reactor-netty的版本确实是:0.9.8.RELEASE(有bug的版本)
三 解决办法:
方法一:升级SpringBoot版本到2.3.4.RELEASE
,顺便把SpringCloud的版本升级到Hoxton.SR8
解决之后的依赖如下:
+--- org.springframework.cloud:spring-cloud-starter-gateway -> 2.2.5.RELEASE | \--- org.springframework.boot:spring-boot-starter-webflux:2.3.2.RELEASE -> 2.3.4.RELEASE | +--- org.springframework.boot:spring-boot-starter-reactor-netty:2.3.4.RELEASE | | \--- io.projectreactor.netty:reactor-netty:0.9.12.RELEASE
方法二:在org.springframework.cloud:spring-cloud-starter-gateway
依赖中exclude掉io.projectreactor.netty:reactor-netty:0.9.8.RELEASE
,并且额外引入io.projectreactor.netty:reactor-netty:0.9.12.RELEASE
依赖。