Exec wait never settles when the Docker stream closes without ending, and Node exits 0

Ouverte Adaptée aux débutants
#1,673 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 4 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
72/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
docker, node.js, typescript
Domaine
backend, testing

Piste de recherche

Trouver DockerContainerClient.waitForExecStreamToEnd, qui, selon l’issue, attend uniquement les événements end ou error du flux. Commencer par suivre la vérification du port en écoute qui appelle cette méthode et voir comment exec.inspect() gère le code de sortie. Le travail est terminé lorsque la fermeture du flux met fin à l’attente et qu’une vérification inachevée est réessayée jusqu’à l’expiration du délai de démarrage.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Expected Behaviour

PostgreSqlContainer.start() resolves, or rejects with an error, when the listening-port check's docker exec stream closes.

Actual Behaviour

Sometimes the internal port check never finishes. DockerContainerClient.waitForExecStreamToEnd waits for the exec stream's end or error event only. When the stream emits close without end, that promise never settles. With nothing else keeping the event loop alive, Node exits with code 0, so a Vitest global setup that starts the container ends the whole run with code 0 before any test runs.

It happened in 3 of 12 CI jobs on one runner provider and none on another. Listening for close too (stream.on("close", res)) fixed it in 12 of 12 jobs. exec.inspect() then reports the exit code, and an unfinished check is retried until the startup timeout.

Testcontainers Logs

The last lines for the Postgres container in a failing job. Nothing follows Health check wait strategy complete, and Internal port 5432/tcp ready is never logged:

testcontainers [DEBUG] [d9f4513e9ba1] Waiting for container to be ready...
testcontainers [DEBUG] [d9f4513e9ba1] Waiting for host port 32772...
testcontainers [DEBUG] [d9f4513e9ba1] Waiting for internal port 5432/tcp...
testcontainers [DEBUG] [d9f4513e9ba1] Host port 32772 ready
testcontainers [DEBUG] [d9f4513e9ba1] Host port wait strategy complete
testcontainers [DEBUG] [d9f4513e9ba1] Health check wait strategy complete

A beforeExit listener showed the event loop draining with only stdio pipes left: beforeExit code=0 active=["PipeWrap","PipeWrap","PipeWrap"]. Nothing called process.exit.

Steps to Reproduce

  1. Start a PostgreSqlContainer with the default wait strategy (health check plus listening ports) in a Vitest globalSetup.
  2. Run it repeatedly on a CI runner whose Docker daemon sometimes closes exec streams without ending them. We saw it on Docker Engine 29.7.2 (API 1.55).
  3. Some runs exit 0 right after Health check wait strategy complete, without running any tests.

Environment Information

  • Operating System: Ubuntu 24.04 (CI runner VM)
  • Container runtime and version: Docker Engine 29.7.2, API 1.55
  • Node version: 26.14.0
  • Test runner and version: Vitest 5.1.2, ESM
  • Testcontainers version: 12.2.2, @testcontainers/postgresql 12.2.2, image ghcr.io/baosystems/postgis:18-3.6
  • Last Testcontainers version where this worked, if any: unknown
Langage dominant
TypeScript
Étoiles
2.7k
Forks
290
Merge moyen
4 j 1 h
PR mergées (30 j)
22

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de testcontainers/testcontainers-node

Toutes les issues de testcontainers/testcontainers-node

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.