[Bug]: GenericContainer.start() and stop() are not thread-safe
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- docker, java
- 領域
- testing-qa
調査の方向性
GenericContainer.start() と stop() から始め、特に issue で説明されている containerId ガードを確認してください。PR #11702 と、@Testcontainers および @Container を使った並行実行の例を確認してください。並行する start と stop の呼び出しが安全で、重複したコンテナを作成せず、共有依存関係を誤って扱わなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
Module
Core
Testcontainers version
2.0.4
Using the latest Testcontainers version?
Yes
What happened?
GenericContainer.start() guards against double-start with if (containerId != null) return, but start() is not synchronized. When two threads call start() on the same container concurrently, both can pass the guard before either sets containerId, creating two Docker containers for one logical dependency.
This can happen when @Testcontainers is used and the container is also started from another context. For example, custom test infrastructure that handles @Container annotations alongside the JUnit extension:
@Testcontainers
class MyTest {
// Custom infrastructure starts this container during context setup.
// The @Testcontainers extension also starts it via Startables.deepStart().
// Both run concurrently - the second start() should be a no-op, but without
// synchronization both threads pass the containerId == null check.
@Container
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:16");
}
The workaround is to not annotate dependencies with @Container when custom infrastructure already handles them, but this is not obvious to developers and error-prone.
I can't provide the exact scenario because we faced this in a closed-source project. The example above illustrates the general pattern.
Additional Information
I submitted a PR with a fix: #11702
- 主要言語
- Java
- スター
- 8.7k
- フォーク
- 1.9k
- 平均マージ
- 17時間 38分
- マージ済み PR(30日)
- 3
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
testcontainers/testcontainers-java のほかの issue
-
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オープンtype/enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
testcontainers/testcontainers-java#11967 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
testcontainers/testcontainers-java#11941 ·
メンテナーはふだん 1 日以内に返信
-
type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
testcontainers/testcontainers-java#11829 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
type/enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
testcontainers/testcontainers-java#11578 ·
メンテナーはふだん 1 日以内に返信
testcontainers/testcontainers-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
grimmory-tools/grimmory#2850 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
aoqia194/leaf-loader#19 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
apache/streampark#4521 ·
-
Update license yearオープン0 - Backlog 1 - Ready documentation good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100