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

未关闭 适合新手
#1,673 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
docker, node.js, typescript
领域
backend, testing

调研方向

找到 DockerContainerClient.waitForExecStreamToEnd,issue指出它只等待流的end或error事件。首先追踪调用它的监听端口检查,并了解exec.inspect()如何处理退出代码。当流关闭后等待结束,且未完成的检查会持续重试直到启动超时,即为完成。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
TypeScript
星标
2.7k
派生
290
平均合并
4 天 1 小时
30 天内合并 PR
22

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

testcontainers/testcontainers-node 的其他 Issue

查看 testcontainers/testcontainers-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。