[Bug]: GenericContainer.start() and stop() are not thread-safe
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- docker, java
- Área
- testing-qa
Línea de trabajo
Comienza con GenericContainer.start() y stop(), especialmente con la protección de containerId descrita en el issue. Revisa el PR #11702 y el ejemplo concurrente de @Testcontainers y @Container; se considera terminado cuando las llamadas concurrentes a start y stop son seguras, no crean contenedores duplicados ni gestionan incorrectamente la dependencia compartida.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Java
- Estrellas
- 8.7k
- Forks
- 1.9k
- Merge medio
- 17 h 38 min
- PR fusionados (30 d)
- 3
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de testcontainers/testcontainers-java
-
type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
testcontainers/testcontainers-java#11997 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Enhancement]: Document why singleton containers are required under Spring's test context cachingAbiertotype/enhancement
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
testcontainers/testcontainers-java#11967 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
testcontainers/testcontainers-java#11941 ·
Los mantenedores suelen responder en 1 día
-
type/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
testcontainers/testcontainers-java#11829 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
type/enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
testcontainers/testcontainers-java#11578 ·
Los mantenedores suelen responder en 1 día
Todos los issues de testcontainers/testcontainers-java
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
MaikuB/flutter_appauth#683 ·
-
type: possible bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
grimmory-tools/grimmory#2850 · 1 comentario ·
Los mantenedores suelen responder en 1 día