child_process: fix custom stdio pipe writable property#64628
Open
mhayk wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_ENDerrors.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:Testing
test-child-process-custom-pipe.js✅This is a pre-existing bug fix without a tracked issue number.