Skip to content

Fix container exec output truncation#1381

Open
cristianrgreco wants to merge 1 commit into
mainfrom
claude/fix-exec-output-truncation
Open

Fix container exec output truncation#1381
cristianrgreco wants to merge 1 commit into
mainfrom
claude/fix-exec-output-truncation

Conversation

@cristianrgreco

Copy link
Copy Markdown
Collaborator

Summary

DockerContainerClient.exec() resolved as soon as the raw multiplexed stream emitted "end", then immediately read the captured chunk arrays. Those arrays are filled by "data" handlers on the demuxed stdout/stderr PassThroughs, which can still be flushing buffered frames at that point — so output/stdout/stderr could be returned truncated under load.

The fix ends the demuxed PassThroughs once the raw stream ends and awaits their completion (stream/promises finished()) before reading the chunks.

Verification

  • Added a deterministic regression test (docker-container-client.test.ts) that reproduces the flush race with a corked PassThrough (no Docker required).
  • Red-green confirmed: pre-fix the captured stdout is empty (truncated); post-fix it is complete.
  • npm ci && npx vitest run packages/testcontainers/src/container-runtime/clients/container/docker-container-client.test.ts1 passed
  • npm run check-compiles → clean · npm run lint → clean

Test results

1 new test passing; red-green evidence captured above.

Not breaking

Internal behaviour fix to an existing method; public API and return shape ({ output, stdout, stderr, exitCode }) unchanged. No consumer-visible signature change.

🤖 Generated with Claude Code

DockerContainerClient.exec() resolved as soon as the raw multiplexed
stream emitted "end", then immediately read the captured chunk arrays.
Those arrays are filled by "data" handlers on the demuxed stdout/stderr
PassThroughs, which can still be flushing buffered frames at that point,
so output/stdout/stderr could be returned truncated.

End the demuxed PassThroughs once the raw stream ends and await their
completion before reading the chunks. Adds a deterministic regression
test reproducing the flush race.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cristianrgreco cristianrgreco added bug Something isn't working patch Backward compatible bug fix labels Jun 22, 2026
@netlify

netlify Bot commented Jun 22, 2026

Copy link
Copy Markdown

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit 0e0e9da
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-node/deploys/6a398607e9dc7a000986ef87
😎 Deploy Preview https://deploy-preview-1381--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Backward compatible bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant