diff options
author | Matteo Collina <hello@matteocollina.com> | 2019-03-15 20:23:15 +0100 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2019-03-25 12:29:16 +0100 |
commit | bdea725bdcb299579547f66ebcc98af16f53cd16 (patch) | |
tree | beaef1835efc40dfb434916547c99c5fb731077a /lib/internal/process | |
parent | cdb87d954804cdba89ed7cd10f28efa5ca5e1f1c (diff) | |
download | android-node-v8-bdea725bdcb299579547f66ebcc98af16f53cd16.tar.gz android-node-v8-bdea725bdcb299579547f66ebcc98af16f53cd16.tar.bz2 android-node-v8-bdea725bdcb299579547f66ebcc98af16f53cd16.zip |
process: make stdout and stderr emit 'close' on destroy
Fix: https://github.com/nodejs/node/issues/26550
PR-URL: https://github.com/nodejs/node/pull/26691
Fixes: https://github.com/false
Fixes: https://github.com/nodejs/node/issues/26550
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/internal/process')
-rw-r--r-- | lib/internal/process/stdio.js | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/internal/process/stdio.js b/lib/internal/process/stdio.js index bf5f6df15f..46c2ba4e9c 100644 --- a/lib/internal/process/stdio.js +++ b/lib/internal/process/stdio.js @@ -2,7 +2,26 @@ exports.getMainThreadStdio = getMainThreadStdio; -function dummyDestroy(err, cb) { cb(err); } +function dummyDestroy(err, cb) { + // SyncWriteStream does not use the stream + // destroy mechanism for some legacy reason. + // TODO(mcollina): remove when + // https://github.com/nodejs/node/pull/26690 lands. + if (typeof cb === 'function') { + cb(err); + } + + // We need to emit 'close' anyway so that the closing + // of the stream is observable. We just make sure we + // are not going to do it twice. + // The 'close' event is needed so that finished and + // pipeline work correctly. + if (!this._writableState.emitClose) { + process.nextTick(() => { + this.emit('close'); + }); + } +} function getMainThreadStdio() { var stdin; |