Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug]: LoggedPullImageResultCallback throws java.lang.ArithmeticException: / by zero

未关闭
#11,416 1 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@arimu1 已经在做这个了。

开始于 2026年7月29日。

  • #11953 来自 @arimu1 —— 未关闭

评估

难度
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 内容生成。

描述

type/bug
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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

testcontainers/testcontainers-java 的其他 Issue

查看 testcontainers/testcontainers-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。