child_process: only stop readable side of stream passed to process by addaleax · Pull Request #27373 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/internal/child_process.js
4 changes: 4 additions & 0 deletions test/parallel/test-child-process-pipe-dataflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const MB = KB * KB;
grep = spawn('grep', ['x'], { stdio: [cat.stdout, 'pipe', 'pipe'] });
wc = spawn('wc', ['-c'], { stdio: [grep.stdout, 'pipe', 'pipe'] });

// Extra checks: We never try to start reading data ourselves.
cat.stdout._handle.readStart = common.mustNotCall();
grep.stdout._handle.readStart = common.mustNotCall();

[cat, grep, wc].forEach((child, index) => {
child.stderr.on('data', (d) => {
// Don't want to assert here, as we might miss error code info.
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-child-process-server-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

const server = net.createServer((conn) => {
conn.on('close', common.mustCall());

spawn(process.execPath, ['-v'], {
stdio: ['ignore', conn, 'ignore']
}).on('close', common.mustCall());
}).on('close', common.mustCall(() => {
conn.end();
}));
}).listen(common.PIPE, () => {
const client = net.connect(common.PIPE, common.mustCall());
client.on('data', () => {
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-child-process-stdio-merge-stdouts-into-cat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { spawn } = require('child_process');

// Regression test for https://github.com/nodejs/node/issues/27097.
// Check that (cat [p1] ; cat [p2]) | cat [p3] works.

const p3 = spawn('cat', { stdio: ['pipe', 'pipe', 'inherit'] });
const p1 = spawn('cat', { stdio: ['pipe', p3.stdin, 'inherit'] });
const p2 = spawn('cat', { stdio: ['pipe', p3.stdin, 'inherit'] });
p3.stdout.setEncoding('utf8');

// Write three different chunks:
// - 'hello' from this process to p1 to p3 back to us
// - 'world' from this process to p2 to p3 back to us
// - 'foobar' from this process to p3 back to us
// Do so sequentially in order to avoid race conditions.
p1.stdin.end('hello\n');
p3.stdout.once('data', common.mustCall((chunk) => {
assert.strictEqual(chunk, 'hello\n');
p2.stdin.end('world\n');
p3.stdout.once('data', common.mustCall((chunk) => {
assert.strictEqual(chunk, 'world\n');
p3.stdin.end('foobar\n');
p3.stdout.once('data', common.mustCall((chunk) => {
assert.strictEqual(chunk, 'foobar\n');
}));
}));
}));
27 changes: 27 additions & 0 deletions test/parallel/test-child-process-stdio-reuse-readable-stdio.js