首页 > 解决方案 > 同时运行的 gradle/geb 测试挂起导致堆积和内存故障“无法获得文件锁定”。

问题描述

我提前为这篇文章的篇幅道歉。

我在增加我的 geb 测试套件中的任务数量时遇到了问题,其中 gradle 似乎无法同时处理多个并发构建。到目前为止,它已经成功运行了 4 年,似乎在我的系统中添加新任务已经达到了某种阈值。最初这开始看起来像是来自 selenoid 网格的连接错误,但在升级版本后,开始出现新的错误消息,使问题更加清晰。如果有人可以帮助解决这个问题,我将不胜感激,我已经做了一个月,似乎无法深入了解它。理想情况下,该解决方案将为进一步扩展留出空间,因为这似乎确实是并发任务的问题。

我会注意到减少计划任务的数量开始解决这个问题,但即使在这一点上,我也没有运行我想要的所有任务。

测试可以正常运行几个小时,然后出现问题的第一个迹象是通过此消息,显示在测试结束时:

Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.

虽然我的测试设置为 7 分钟后超时(4 分钟是预期的运行时间),但构建开始需要越来越长的时间才能完成,从 25 分钟开始持续长达 4 小时(随着容器接近内存而增加限制)。

在其中一些消息之后,这些消息开始出现(敏感信息已编辑):

[redacted]TestReport: Timeout waiting to lock daemon addresses registry. It is currently in use by another Gradle instance.
Feb 18 15:10:35 ip-172-30-3-121 [redacted]TestReport: Owner PID: 21092
Feb 18 15:10:35 ip-172-30-3-121 [redacted]TestReport: Our PID: 21030
Feb 18 15:10:35 ip-172-30-3-121 [redacted]TestReport: Owner Operation: 
Feb 18 15:10:35 ip-172-30-3-121 [redacted]TestReport: Our operation: 
Feb 18 15:10:35 ip-172-30-3-121 [redacted]TestReport: Lock file: /root/.gradle/daemon/6.8.2/registry.bin.lock

我相信这与竞争锁定文件的任务有关,这些任务完成的时间越来越长,在前一个任务运行时启动了更多任务,最终导致 docker 容器完全耗尽内存。

每个 gradle 任务最多占用 400mb,但即便如此,也没有足够的任务为此安排,仅由于一次运行的任务太多而导致内存故障

除了 cron 任务的安排和包括我有哪些 gradle 设置之外,我认为没有太多代码可以帮助解决这个问题。

我尝试解决这个问题是从升级到最新的兼容版本开始的,这导致了 2 周的依赖地狱,所以版本号反映了这一点。

我试图解决这个问题的方法:

我认为会有所帮助的事情

代码和基础设施

堆:

系统工作原理的总体思路

cron 计划

*/5 * * * * root cd /tests ; ./gradlew clean test --tests [test1] -Dtest.single=[test1] -DenableVideo=true -Denvironment=http://[hub address]/wd/hub -Dbrowser=chrome   --no-build-cache  --stacktrace --info 2>&1 | logger -t [test1] ; ./gradlew report --no-build-cache --stacktrace --info  2>&1  | logger -t [test1]Report

*/11 * * * * root cd /tests ; ./gradlew clean test --tests [test2] -Dtest.single=[test2] -DenableVideo=true -Denvironment=http://[hub address]/wd/hub -Dbrowser=chrome --no-build-cache  --stacktrace --info  2>&1 | logger -t [test2] ; ./gradlew report  -DclassName=[test2] --no-build-cache --stacktrace --info  2>&1  | logger -t [test2]Report

*/8 * * * * root cd /tests ; ./gradlew clean test --tests [test3] -Dtest.single=[test3] -Denvironment=http://[hub address]/wd/hub -DenableVideo=true -Dbrowser=chrome --no-build-cache  --stacktrace --info  2>&1 | logger -t [test3] ; ./gradlew report -DclassName=[test3]  --no-build-cache --stacktrace --info  2>&1 | logger -t [test3]Report

3 * * * * root cd /tests ; ./gradlew clean test --tests [test4] -Dtest.single=[test4] -DenableVideo=true -Denvironment=http://[redacted]/wd/hub -Dbrowser=chrome --no-build-cache  --stacktrace --info  2>&1 | logger -t [test4] ; ./gradlew report -DclassName=[test4] --no-build-cache --stacktrace --info   2>&1  | logger -t [test4]Report

8 * * * * root cd /tests ; ./gradlew clean test --tests [test5] -Dtest.single=[test5] -DenableVideo=true -Denvironment=http://[redacted]/wd/hub -Dbrowser=chrome --stacktrace --info  2>&1 | logger -t [test5] ; ./gradlew report -DclassName=[test5] --no-build-cache --stacktrace --info   2>&1  | logger -t [test5]Report

gradle 基础设施(来自构建扫描)

Background build scan publication   On  
Build Cache On  
Daemon  On  
Configuration Cache Off 
Configure on demand Off 
Continue on failure Off 
Continuous  Off 
Dry run Off 
File system watching    Off 
Offline Off 
Parallel    Off 
Re-run tasks    Off 
Refresh dependencies    Off 
Task inputs file capturing  Off

ecs/docker 基础设施

Operating system    Linux 4.14.33-51.37.amzn1.x86_64    
CPU cores   1 core  
Max Gradle workers  1 worker    
Java runtime    Ubuntu OpenJDK Runtime Environment 11.0.10+9-Ubuntu-0ubuntu1.20.04  
Java VM Ubuntu OpenJDK 64-Bit Server VM 11.0.10+9-Ubuntu-0ubuntu1.20.04 (mixed mode, sharing)   
Max JVM memory heap size    1.9 GiB 
Locale  English (United States) 
Default charset US-ASCII    
Username    root

这是我的项目基于的示例项目:

https://github.com/geb/geb-example-gradle

如果您能提供帮助,非常感谢您抽出宝贵的时间。

标签: gradleautomated-testsgeb

解决方案


推荐阅读