mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
stream: complete pipeline with stdio
stdio (stderr & stdout) should for compatibility reasons not be closed/end():ed. However, this causes pipeline with a stdio destination to never finish. This commit fixes this issue at a performance cost. Refs: https://github.com/nodejs/node/issues/7606 Fixes: https://github.com/nodejs/node/issues/32363 PR-URL: https://github.com/nodejs/node/pull/32373 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
f675e3a365
commit
98b6b2d840
2 files changed
+36
No files matched your search
@@ -267,6 +267,13 @@ function pipeline(...streams) {
|
||||
} else if (isStream(stream)) {
|
||||
if (isReadable(ret)) {
|
||||
ret.pipe(stream);
|
||||
|
||||
// Compat. Before node v10.12.0 stdio used to throw an error so
|
||||
// pipe() did/does not end() stdio destinations.
|
||||
// Now they allow it but "secretly" don't close the underlying fd.
|
||||
if (stream === process.stdout || stream === process.stderr) {
|
||||
ret.on('end', () => stream.end());
|
||||
}
|
||||
} else {
|
||||
ret = makeAsyncIterable(ret);
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const os = require('os');
|
||||
|
||||
if (process.argv[2] === 'child') {
|
||||
const { pipeline } = require('stream');
|
||||
pipeline(
|
||||
process.stdin,
|
||||
process.stdout,
|
||||
common.mustCall((err) => {
|
||||
assert.ifError(err);
|
||||
})
|
||||
);
|
||||
} else {
|
||||
const cp = require('child_process');
|
||||
cp.exec([
|
||||
'echo',
|
||||
'hello',
|
||||
'|',
|
||||
`"${process.execPath}"`,
|
||||
`"${__filename}"`,
|
||||
'child'
|
||||
].join(' '), common.mustCall((err, stdout) => {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(stdout.split(os.EOL).shift().trim(), 'hello');
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user