mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
cc7b3fbaab
Closing the underlying resource completely has the unwanted side effect that the stream can no longer be used at all, including passing it to other child processes. What we want to avoid is accidentally reading from the stream; accordingly, it should be sufficient to stop its readable side manually, and otherwise leave the underlying resource intact. Fixes: https://github.com/nodejs/node/issues/27097 Refs: https://github.com/nodejs/node/pull/21209 PR-URL: https://github.com/nodejs/node/pull/27373 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
'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');
|
|
}));
|
|
}));
|
|
}));
|