testcontainers / testcontainers/testcontainers-python

Bug: Starting multiple containers at once in parallel causes Conflict by starting ryuk container multiple times due to race condition

Abierto
#746 5 comentarios 4 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Python
Estrellas
2.3k
Forks
386
Merge medio
4 h 40 min
PR fusionados (30 d)
1

Descripción

Describe the bug

Starting two testcontainers at once triggers both of them to call Reaper._create_instance close in time. Both Reaper instances attempt to create the same ryuk container (since SESSION_ID is the same).

This is relevant when using pytest-parallel, which my organization does. I can probably work around the problem by serializing testcontainer start() calls on one thread.

To Reproduce

from testcontainers.postgres import PostgresContainer
import concurrent.futures


def start_postgres_container(port: int):
    with PostgresContainer(port=port) as postgres:
        print("Postgres is running on port", postgres.get_exposed_port(port))


with concurrent.futures.ThreadPoolExecutor() as executor:
    future1 = executor.submit(start_postgres_container, port=5400)

    # Uncommenting this reliably avoids the error
    # import time
    # time.sleep(5)
    future2 = executor.submit(start_postgres_container, port=5401)
    future1.result()
    future2.result()

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

# Get the operating system information (on a unix os).
$ uname -a
Darwin xxx 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020 arm64 arm Darwin
$ python --version
Python 3.11.10
$ docker info
# Get all python packages.
$ pip freeze
certifi==2024.8.30
charset-normalizer==3.4.0
docker==7.1.0
idna==3.10
requests==2.32.3
testcontainers==4.8.2
typing_extensions==4.12.2
urllib3==2.2.3
wrapt==1.17.0

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con Reaper._create_instance y ejecuta la reproducción de concurrent.futures del issue usando dos instancias de PostgresContainer. Se considera terminado cuando los inicios concurrentes ya no producen un Conflict al intentar crear el contenedor ryuk varias veces y ambos contenedores se inician correctamente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
docker, python
Área
testing-qa
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.