Spring Boot Admin - 系统错误中打开的文件过多

Posted

技术标签:

【中文标题】Spring Boot Admin - 系统错误中打开的文件过多【英文标题】:Spring Boot Admin - Too Many open Files In System Error 【发布时间】:2020-10-20 14:51:09 【问题描述】:

我正在尝试在 ECS Fargate 上运行 spring-boot-admin - 几分钟后服务器死机并且日志中充满了“系统中打开的文件过多”错误。

我使用的是 spring-boot 2.3.1,并且已经尝试了 spring-boot-admin 的 2.2.3 和 2.3.0-SNAPSHOT。该 jar 在安装了 openjdk-11-jdk-headless 的 ubuntu 20.04 基础映像上运行。 ECS 服务有 2gb RAM 可用,我增加了 nofile 和 nproc 的 Ulimits (100000)

      Ulimits:
        - Name: nofile
          HardLimit: 1000000
          SoftLimit: 1000000
        - Name: nproc
          HardLimit: 1000000
          SoftLimit: 1000000

堆栈跟踪:

2020-06-29 22:03:35.691 ERROR 6 --- [io-8080-exec-24] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is io.netty.channel.ChannelException: io.netty.channel.unix.Errors$NativeIoException: newSocketStream(..) failed: Too many open files in system] with root cause io.netty.channel.unix.Errors$NativeIoException: newSocketStream(..) failed: Too many open files in system 2020-06-29 22:03:36.345 ERROR 6 --- [io-8080-exec-14] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is io.netty.channel.ChannelException: io.netty.channel.unix.Errors$NativeIoException: newSocketStream(..) failed: Too many open files in system] with root cause io.netty.channel.unix.Errors$NativeIoException: newSocketStream(..) failed: Too many open files in system 2020-06-29 22:03:36.350 ERROR 6 --- [o-8080-Acceptor] org.apache.tomcat.util.net.Acceptor : Socket accept failed java.io.IOException: Too many open files in system at java.base/sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method) ~[na:na] at java.base/sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:533) ~[na:na] at java.base/sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:285) ~[na:na] at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:469) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36] at org.apache.tomcat.util.net.NioEndpoint.serverSocketAccept(NioEndpoint.java:71) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36] at org.apache.tomcat.util.net.Acceptor.run(Acceptor.java:95) ~[tomcat-embed-core-9.0.36.jar!/:9.0.36] at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

我有一组 8 个微服务与 sba 客户端连接(目前没有安全性),用于 3 个环境(总共 24 个实例)。只有客户端中的设置是:

spring.boot.admin.client.instance.prefer-ip=true
spring.boot.admin.client.url=https://xxxxx.com
spring.boot.admin.client.instance.name=
spring.boot.admin.client.instance.metadata.tags.environment=$spring.profiles.active

我已启用首选 IP,因为这些实例中的大多数都不在 Eureka 或负载均衡器之后,并且只是处理队列外的数据。

服务器只设置了spring.boot.admin.ui.public-url

在最初的几分钟内,一切正常 - 但随后这些错误开始发生,一切都崩溃了。 Cloudwatch 指标显示 cpu 达到 100%,然后 sba 上的目标组健康检查失败,ECS 重新启动任务。目前这需要大约 30 分钟。

从默认值提高 ulimit 增加了应用程序崩溃之前的时间,但它最终还是会崩溃 - 就好像它的套接字/连接泄漏一样。

我没有任何运行 webflux / netty 应用程序的经验 - 我有什么遗漏吗?我需要设置更高的ulimit吗?

【问题讨论】:

【参考方案1】:

我遇到了同样的问题,发现在 spring boot 中记录了一个问题:Many File Open Issue : Spring Boot 2.3.0 -> Spring Boot 2.3.1 #21934

在新版本发布之前,将 reactor-netty 升级到 0.9.9.RELEASE 应该可以修复它,为我做了!

【讨论】:

我用 0.9.9.RELEASE 交换了 reactor-netty,问题依旧。【参考方案2】:

我遇到了同样的问题,不幸的是,将 reactor-netty 更新为 0.9.9.RELEASE 并没有解决问题,而是降级为 0.9.7.RELEASE

【讨论】:

以上是关于Spring Boot Admin - 系统错误中打开的文件过多的主要内容,如果未能解决你的问题,请参考以下文章

SpringCloud微服务监控Spring Boot Admin

spring boot 学习 ---- spring boot admin

Spring Boot Admin 添加报警提醒和登录验证功能!

spring boot 2.0.3+spring cloud (Finchley)7微服务监控Spring Cloud Admin

实战:使用Spring Boot Admin实现运维监控平台

Spring Boot + Spring Cloud 实现权限管理系统 后端篇(二十三):配置中心(ConfigBus)