Skip to content

node:worker_threads: expose Worker stdio streams and option state #3330

Closed

Description

@andrewtdiz

Summary

new Worker(filename, options) should honor Node-observable Worker option surfaces such as stdout, stderr, stdin, env, resourceLimits, name, SHARE_ENV, and trackUnmanagedFds. Perry currently has no Node-compatible Worker constructor, so these stream and option-state rows are untracked outside the broad worker execution issue.

Node Behavior

A Node v25.9.0 probe shows the stream and option shape:

const { Worker, SHARE_ENV } = require("node:worker_threads");
console.log(typeof SHARE_ENV, String(SHARE_ENV)); // symbol Symbol(nodejs.worker_threads.SHARE_ENV)

const worker = new Worker(`
  const { parentPort } = require("node:worker_threads");
  process.stdout.write("out-line\\n");
  process.stderr.write("err-line\\n");
  parentPort.postMessage({ envProbe: process.env.PERRY_WORKER_ENV_PROBE || null });
`, {
  eval: true,
  stdout: true,
  stderr: true,
  env: { PERRY_WORKER_ENV_PROBE: "child" },
  resourceLimits: { maxOldGenerationSizeMb: 16 },
  name: "stdio-probe",
});

console.log(!!worker.stdout, !!worker.stderr, worker.stdin === null);
console.log(worker.threadName, Object.keys(worker.resourceLimits).sort());

Node exposes readable stdout/stderr streams when requested, leaves stdin null unless requested, preserves threadName, exposes resource-limit keys, and applies the supplied environment to worker code.

Perry Behavior

docs/runtime-parity-gaps.md lists Worker stdin, stdout, stderr, resourceLimits, threadName, SHARE_ENV, and option rows as missing. #3156 tracks the basic Worker file execution and parentPort lifecycle but does not explicitly cover stdio stream plumbing, SHARE_ENV, or advanced option state. Source search found environment-data and synthetic parentPort shims, plus recently merged main-thread isMainThread / threadId / resourceLimits shape support, but no Worker constructor option implementation. Exact issue/PR searches for worker.stdin, worker.stdout, worker.stderr, trackUnmanagedFds, and worker_threads resource options found no focused tracker beyond #2507/#3156.

Suggested PR Cut

Batch this with related issues in:
node:worker_threads: Worker execution and option surface parity cut

Good batch candidates:

Do not batch with:

  • unrelated modules
  • broad subsystem rewrites
  • fixes needing different test harnesses
  • MessagePort / BroadcastChannel delivery unless needed for Worker message basics
  • Web Locks APIs
  • Perry-native perry/thread API changes unless required as implementation plumbing

Acceptance

  • parity/regression test starts a Worker with stdout: true and stderr: true and observes readable stream output matching Node for a deterministic fixture
  • Worker option state for env, name / threadName, resourceLimits, stdin, and SHARE_ENV matches Node-observable behavior for covered cases
  • implementation matches Node observable behavior
  • related known-failure/docs/manifest entries updated if touched

Activity

  1. andrewtdiz commented on May 30, 2026

    @andrewtdiz
    ContributorAuthor

    Related module-state leaf: #3395 covers main-thread worker_threads value exports (isInternalThread, parentPort, threadName, workerData, SHARE_ENV) reading as undefined. This is a natural same-PR candidate if the option-surface work also normalizes Worker/module state values.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions