[Bug]: LoggedPullImageResultCallback throws java.lang.ArithmeticException: / by zero
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 58/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- docker, java
- 领域
- testing-qa
调研方向
从 core/src/main/java/org/testcontainers/images/LoggedPullImageResultCallback.java 开始,重点查看第 113 行和第 121 行附近的持续时间计算以及 onComplete 方法。检查现有的 Core 测试约定,为在一秒内完成的 pull 增加覆盖,并运行相关的 Core 测试,以确认完成时不再抛出 ArithmeticException。
由索引模型根据 Issue 内容生成。
描述
Module
Core
Testcontainers version
1.21.3
Using the latest Testcontainers version?
Yes
Host OS
Linux
Host Arch
x86
Docker version
Docker Client 28.0.4
Docker Server 28.0.4
What happened?
When running tests in GitHub actions, it fails due to line 121 in LoggedPullImageResultCallback throws an java.lang.ArithmeticException: / by zero. Out of 10 times running our tests, it has failed 8 times and succeeded2. I have not been able to reproduce this in a reliable way but it seems like this would happen if a pull takes less than one full second since duration will become 0.
My first hypothesis was that this could happen if one already pulled the image in question but it seems that if the image is found locally, completed will never be set to true and therefore the line that throws the exception will never be executed.
Our current hypothesis is that there could be a race condition if a pull of an image is triggered twice. So just before the first pull invocation completes, another process triggers a pull. It's not fully found locally so we'll enter the "pull flow" but just at the last second, causing it to complete less in less than a second and trigger this issue.
If my hypothesis is correct it's hard to reliably create a way to replicate this but I think it would be worth it to be a bit more defensive in this part of the code and not throw an exception if it happens that a pull takes less than a second.
Relevant log output
OurTestClass > initializationError FAILED
org.opentest4j.AssertionFailedError: failed to start service!
at app//xx.xxxxxx.ourlibrary.integrationtests.IntegrationTestPostProcessor.postProcessTestInstance(IntegrationTestPostProcessor.java:112)
at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at [email protected]/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at [email protected]/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at [email protected]/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
at [email protected]/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at [email protected]/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at [email protected]/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at [email protected]/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at [email protected]/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at [email protected]/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at [email protected]/java.util.Optional.orElseGet(Optional.java:364)
at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by:
java.lang.ArithmeticException: / by zero
at org.testcontainers.images.LoggedPullImageResultCallback.onComplete(LoggedPullImageResultCallback.java:120)
at org.testcontainers.images.TimeLimitedLoggedPullImageResultCallback.onComplete(TimeLimitedLoggedPullImageResultCallback.java:91)
at xx.xxxxxx.ourlibrary.integrationtests.testcontainers.ReactivePullImageResultCallback.onComplete(ReactivePullImageResultCallback.java:17)
at org.testcontainers.shaded.com.github.dockerjava.core.exec.AbstrAsyncDockerCmdExec$1.onComplete(AbstrAsyncDockerCmdExec.java:51)
at org.testcontainers.shaded.com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:276)
at java.base/java.lang.Thread.run(Thread.java:1583)
Additional Information
No response
- 主要语言
- Java
- 星标
- 8.7k
- 派生
- 1.9k
- 平均合并
- 17 小时 38 分钟
- 30 天内合并 PR
- 3
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
testcontainers/testcontainers-java 的其他 Issue
-
[Bug]: Build fails with "Unknown cli flag: --scripts-prepend-node-path" due to outdated Spotless plugin可能已有人在做 @dhruv9b 于 35 天前认领。 未关闭type/bug
难度 2/5 1-3 小时 新手友好度 78/100
testcontainers/testcontainers-java#11997 · 1 条评论 ·
维护者通常 1 天内回复
-
[Enhancement]: Document why singleton containers are required under Spring's test context caching可能已有人在做 @zakaullah075 于 52 天前认领。 未关闭type/enhancement
难度 1/5 1 小时以内 新手友好度 85/100
testcontainers/testcontainers-java#11967 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: Cannot reuse Selenium BrowserWebDriverContainers under Linux可能已有人在做 @kdelay 于 74 天前认领。 未关闭type/bug
难度 2/5 1-3 小时 新手友好度 78/100
testcontainers/testcontainers-java#11941 ·
维护者通常 1 天内回复
-
[Bug]: DockerDesktopClientProviderStrategy is always applicable可能已有人在做 @seonwooj0810 于 123 天前认领。 未关闭type/bug
难度 2/5 1-3 小时 新手友好度 74/100
testcontainers/testcontainers-java#11829 · 1 条评论 ·
维护者通常 1 天内回复
-
[Enhancement]: cleanup document after removing junit4 support可能已有人在做 @SJvaca30 于 130 天前认领。 未关闭type/enhancement
难度 2/5 1-3 小时 新手友好度 65/100
testcontainers/testcontainers-java#11578 ·
维护者通常 1 天内回复
查看 testcontainers/testcontainers-java 的全部 Issue
相似的 Issue
-
component/operate kind/feature-request
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
Forge coverage prompts carry text the agent cannot act on可能已有人在做 @graalvmbot 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
oracle/graalvm-reachability-metadata#10572 ·
维护者通常 1 天内回复
-
[CI] Core CI doesn't run for changes to amoro-format-lance (and amoro-web)可能已有人在做 @MarkAlex1234 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
-
area/docs
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复