在 GitHub Actions 和 Ubuntu 上运行 go test 时出现了“打开的文件太多”错误。

huangapple go评论86阅读模式
英文:

Too many open files error when running go test in github actions and ubuntu

问题

我们已经构建了一个测试套件,在本地的Ubuntu机器和GitHub Actions上的Ubuntu机器上始终正常工作。由于最新添加了单元测试,一个包的单元测试数量相当大,开始出现“打开的文件太多”错误消息:

{"Time":"2021-10-22T13:24:15.784106437Z","Action":"output","Package":"github.com/MyCompany/Product/src/interface/service/user","Test":"Test_userService_MethodTest/Case_1","Output":"2021/10/22 13:24:15 too many open files\n"}

出现了两个奇怪的情况:在Windows上没有这个问题。如果我在错误中提到的包中注释掉一半的单元测试,问题也不会发生。

受影响的包中的单元测试数量目前为245个,大约在这个数量左右停止工作。

英文:

We have buitl a test suite that always worked on local ubuntu machines and on ubuntu machines on github actions. Since the latest additions of unit tests the number of unit tests of one package grew quite substantially and it starts to fail with a too many open files error message:

{"Time":"2021-10-22T13:24:15.784106437Z","Action":"output","Package":"github.com/MyCompany/Product/src/interface/service/user","Test":"Test_userService_MethodTest/Case_1","Output":"2021/10/22 13:24:15 too many open files\n"}

Two strange things appear: On Windows there is no such problem. And if I comment out half of the unit tests in the package mentioned in the error it does not happen either.

The number of unit tests in the affected package is 245 for now and it approximately stops working at around or so.

答案1

得分: 1

我认为你需要更改最大文件描述符。在许多开发虚拟机中都出现了相同的问题,需要更改文件描述符的最大值,而不是inotify设置。

请注意ulimit != ulimit -n

➜  cmd git:(wip-poop) ✗ ulimit -a
-t: CPU时间(秒)              无限制
-f: 文件大小(块)              无限制
-d: 数据段大小(KB)          无限制
-s: 栈大小(KB)             8192
-c: 核心文件大小(块)         0
-v: 地址空间(KB)          无限制
-l: 锁定内存大小(KB)  无限制
-u: 进程数                       1418
-n: 文件描述符                4864
英文:

I think you need to change your max file descriptors. This same problem occurred in many of the development VM's before and needed to change the file descriptors max, not anything with inotify settings.

Note ulimit != ulimit -n

➜  cmd git:(wip-poop) ✗ ulimit -a
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       1418
-n: file descriptors                4864

答案2

得分: 0

在我们的测试设置中,我们为每个子测试注入了一个单独的viper实例来打开一些文件。集中定义一个viper实例,然后将配置传递给测试就解决了这个问题。

英文:

In our test setup we had the config injected by a separate viper instance for each subtest which opened some files everytime. Centrally defining one viper instance and then pass the config down into the tests did the trick.

huangapple
  • 本文由 发表于 2021年10月22日 21:31:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/69677795.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定