Bug: MongoDB container is reported ready before the server accepts connections
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 65/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- Python
- Étoiles
- 2.3k
- Forks
- 386
- Merge moyen
- 4 h 40 min
- PR mergées (30 j)
- 1
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de testcontainers/testcontainers-python
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
testcontainers/testcontainers-python#1115 · 1 réaction ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
Updating the documentation Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
testcontainers/testcontainers-python#1086 · 1 commentaire ·
-
Bug: [minio] _healthcheck calls for nested wait_container_is_ready resulting in long wait time Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
testcontainers/testcontainers-python#578 · 5 commentaires ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 76/100
Toutes les issues de testcontainers/testcontainers-python
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 75/100
-
hcocena Ouvertepolicies-accepted pre-review precheck-passed
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
Bioconductor/BiocContributions#214 · 5 commentaires ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
TencentCloud/Octop#1169 · 1 commentaire ·
-
[开源推荐] 在老板拷问你之前,先让 AI 灵魂拷问你 Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
521xueweihan/HelloGitHub#3778 ·
-
The version checker's trailing attribute region has no control for a less-than inside a quoted value Ouvertearea: dashboard area: tests bug perceived difficulty: 2 python
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Nitjsefnie-Harness-Commons/daedalus#1105 · 1 commentaire ·