Skip to content

fix(ext/node): forward stdout from worker_threads to parent#32160

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

fix(ext/node): forward stdout from worker_threads to parent#32160
bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju:fix/worker-threads-stdout-forwarding

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

@bartlomieju bartlomieju commented Feb 13, 2026

Closes #31889

Summary

  • Adds stdout and stderr as Readable streams on the Worker class, and stdin (null by default), matching the Node.js API surface
  • Forwards process.stdout.write() and process.stderr.write() from worker threads to the parent via internal messages, so worker.stdout/worker.stderr emit data and support .pipe()
  • Closes stdio streams with push(null) when the worker exits
  • Fixes execArgv validation to skip non-flag arguments (e.g. "node" and "development" in --conditions node --conditions development)
  • Enables test-worker-no-stdin-stdout-interaction.js node_compat test

Test plan

  • cargo test --test node_compat parallel -- --filter test-worker-no-stdin-stdout-interaction.js
  • cargo test --test node_compat parallel -- --filter test-worker-execargv (no regression)
  • Vitest 4 threads pool works end-to-end with reproduction repo

🤖 Generated with Claude Code

bartlomieju and others added 2 commits February 13, 2026 20:05
Previously only stderr was forwarded from worker threads to the parent.
This adds stdout forwarding using the same mechanism, enabling
worker.stdout to emit data events when the worker writes to
process.stdout. Also adds the stdin property (null by default) to match
Node.js Worker API surface.

Enables test-worker-no-stdin-stdout-interaction.js node_compat test.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…able for worker stdio

The execArgv validation was treating all array elements as flags, but
items like "node" and "development" are arguments to preceding flags
(e.g. "--conditions node"). Skip items that don't start with '-'.

Also upgrade worker.stdout and worker.stderr from EventEmitter to
Readable streams to match the Node.js API (supporting pipe/unpipe).
Close stdio streams when the worker exits.

This fixes vitest 4 compatibility where threads pool passes
"--conditions node --conditions development" in execArgv and calls
worker.stdout.pipe().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@fraidev fraidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bartlomieju bartlomieju merged commit 7a048f4 into denoland:main Feb 14, 2026
23 checks passed
@bartlomieju bartlomieju deleted the fix/worker-threads-stdout-forwarding branch February 14, 2026 10:03
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.

worker_threads.Worker in Deno’s Node-compat layer lacks stdout/stderr, breaking Vitest threads pool

2 participants