Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Bug: MongoDB container is reported ready before the server accepts connections

Abierto
#1,122 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
docker, mongodb, python
Área
devops, testing

Línea de trabajo

Look at the MongoDbContainer class in testcontainers/mongodb.py to understand the current wait strategy. The fix involves updating the wait strategy to check for the 'Listening on' log entry with address '0.0.0.0' in JSON logs. Run the provided reproduction script to verify the bug and test the fix. Ensure the change works for MongoDB 4.4 and newer versions.

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

Descripción

Describe the bug

When a root user is configured, which MongoDbContainer always does, the mongo image starts twice. A temporary server listening only on localhost creates the user and exits, then the real server starts. Both log "Waiting for connections", and the container's wait strategy matches the first one. So start() returns while no server is reachable from outside the container, and on a slow host the client times out before the real server is up.

I expected start() to return once the real server accepts connections. A line only the real server logs is the "Listening on" entry with address 0.0.0.0 (JSON logs, MongoDB 4.4 and newer), and waiting for r'"Listening on".*"address":"0\.0\.0\.0"' makes the snippet below pass.

To Reproduce

from testcontainers.mongodb import MongoDbContainer

# Limit the container to a tenth of a CPU, as a busy CI runner would.
with MongoDbContainer("mongo:7").with_kwargs(nano_cpus=100_000_000) as mongo:
    client = mongo.get_connection_client()
    print(client.admin.command("ping"))
pymongo.errors.ServerSelectionTimeoutError: localhost:50264: [Errno 54] Connection reset by peer (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s

It fails every time at this limit and passes with nano_cpus=1_000_000_000.

Runtime environment

macOS 26 (arm64), Docker 29.7.2, Python 3.14.0, testcontainers 4.15.0. The wait strategy on main is the same.

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

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.

Más de testcontainers/testcontainers-python

Todos los issues de testcontainers/testcontainers-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.