Skip to content

fix(ext/node): add worker_threads stdin support#32165

Merged
bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju:fix/worker-threads-stdin
Feb 14, 2026
Merged

fix(ext/node): add worker_threads stdin support#32165
bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju:fix/worker-threads-stdin

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

Summary

  • Adds worker.stdin support when { stdin: true } is passed to the Worker constructor
  • Parent creates a Writable stream (worker.stdin) that sends WORKER_STDIN / WORKER_STDIN_END messages to the worker via postMessage
  • Worker replaces process.stdin with a Readable that receives data from those messages, using an early addEventListener with stopImmediatePropagation() to hide internal messages from user handlers
  • Fixes stdout/stderr forwarding to preserve binary data (passes chunk directly instead of String(chunk))
  • Enables 3 new passing node_compat tests: test-worker-stdio.js, test-worker-stdio-flush.js, test-worker-stdio-flush-inflight.js

Test plan

  • cargo test --test node_compat parallel -- --filter "test-worker-stdio" — 3 new tests pass
  • cargo test --test node_compat parallel -- --filter "test-worker-no-stdin-stdout-interaction" — existing test still passes
  • tools/lint.js passes
  • tools/format.js passes

🤖 Generated with Claude Code

When `{ stdin: true }` is passed to the Worker constructor, creates a
writable `worker.stdin` stream that pipes data to the worker's
`process.stdin` via internal WORKER_STDIN/WORKER_STDIN_END messages.

Also fixes stdout/stderr forwarding to preserve binary data instead of
converting to String(), enabling correct transfer of binary content
through worker stdio pipes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju force-pushed the fix/worker-threads-stdin branch from 450ab0d to d594eed Compare February 14, 2026 17:39
@bartlomieju bartlomieju merged commit e3fda85 into denoland:main Feb 14, 2026
86 checks passed
@bartlomieju bartlomieju deleted the fix/worker-threads-stdin branch February 14, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants