Skip to content

child_process: fix custom stdio pipe writable property#64628

Open
mhayk wants to merge 1 commit into
nodejs:mainfrom
mhayk:fix/child_process_custom_pipe
Open

child_process: fix custom stdio pipe writable property#64628
mhayk wants to merge 1 commit into
nodejs:mainfrom
mhayk:fix/child_process_custom_pipe

Conversation

@mhayk

@mhayk mhayk commented Jul 20, 2026

Copy link
Copy Markdown

Problem

When a parent process spawns a child with custom stdio pipes (stdio index >= 3), those pipes are created as readable-only instead of writable. This prevents the parent from writing to the child's custom pipes and causes ERR_STREAM_WRITE_AFTER_END errors.

Root Cause

The socket creation logic simplified the readable property calculation to i > 0, treating all non-stdin streams as readable. This is correct for stdout/stderr (parent reads from child) but incorrect for custom pipes (parent writes to child by default).

Solution

Pass the stdio index to createSocket() and determine socket readability based on the index:

  • stdin (0): readable=false, writable=true (parent writes)
  • stdout/stderr (1,2): readable=true, writable=false (parent reads)
  • custom pipes (3+): readable=false, writable=true (parent writes by default)

Testing

  • New regression test: test-child-process-custom-pipe.js
  • All 110 child_process tests pass ✅
  • All stdin-related tests pass ✅

This is a pre-existing bug fix without a tracked issue number.

When creating custom stdio pipes (index >= 3), the socket was incorrectly
marked as readable instead of writable. This prevented the parent process
from writing to custom child pipes, causing ERR_STREAM_WRITE_AFTER_END errors.

The root cause was in the socket creation logic which simplified the
readable property to `i > 0` (true for all non-stdin), without distinguishing
between:
- stdout/stderr (index 1,2): parent reads from child
- custom pipes (index >= 3): parent writes to child by default

Solution: Pass the stdio index to createSocket() and determine readability
based on the index:
- stdin (0): readable=false (parent writes)
- stdout/stderr (1,2): readable=true (parent reads)
- custom pipes (3+): readable=false (parent writes)

This preserves the original socket semantics while fixing the custom pipe bug.

Fixes: Pre-existing bug (no issue number)
Regression-Test: test/parallel/test-child-process-custom-pipe.js
@nodejs-github-bot nodejs-github-bot added child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. labels Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants