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

Aperta Adatta ai principianti
#1,673 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, node.js, typescript
Ambito
backend, testing

Direzione di ricerca

Individua DockerContainerClient.waitForExecStreamToEnd, che, secondo l’issue, attende solo gli eventi end o error dello stream. Inizia seguendo il controllo della porta in ascolto che chiama questo metodo e il modo in cui exec.inspect() gestisce il codice di uscita. Il lavoro è completato quando la chiusura dello stream termina l’attesa e un controllo non completato viene ripetuto fino alla scadenza del timeout di avvio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
TypeScript
Stelle
2.7k
Fork
290
Merge medio
4g 1h
PR unite (30g)
22

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-node

Tutte le issue di testcontainers/testcontainers-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.