[Bug]: GenericContainer.start() and stop() are not thread-safe
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- docker, java
- Lĩnh vực
- testing-qa
Hướng nghiên cứu
Bắt đầu với GenericContainer.start() và stop(), đặc biệt là guard containerId được mô tả trong issue. Xem lại PR #11702 và ví dụ đồng thời với @Testcontainers và @Container; được xem là hoàn tất khi các lệnh gọi đồng thời tới start và stop an toàn, không tạo các container trùng lặp và không xử lý sai dependency dùng chung.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Java
- Star
- 8.7k
- Fork
- 1.9k
- Merge trung bình
- 2 ngày 17 giờ
- Pull request đã merge (30 ngày)
- 9
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của testcontainers/testcontainers-java
-
type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
testcontainers/testcontainers-java#11997 · 1 bình luận ·
-
[Enhancement]: Document why singleton containers are required under Spring's test context caching Đang mởtype/enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
testcontainers/testcontainers-java#11967 ·
-
type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
testcontainers/testcontainers-java#11941 ·
-
type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
testcontainers/testcontainers-java#11829 · 1 bình luận ·
-
type/enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
testcontainers/testcontainers-java#11578 ·
Tất cả issue của testcontainers/testcontainers-java
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
apache/cloudstack#14222 ·
-
[BUG]茶杯方块在取茶时会引发崩溃 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Cannot differ own consent and managed consents in My Consents view and detailed consent view. Đang mở1.0.0-alpha2 Type/Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
wso2/dpdp-accelerator#272 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
apache/rocketmq-dashboard#4860 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
infinispan/infinispan#18150 ·