Skip to content

stream: fix end-of-stream for silent `.destroy()`

Rodrigo Muino Tomonari requested to merge github/fork/tadjik1/issue-26550 into master

Each stream can get emitClose option which, when set in false will prevent stream to emit close event in case if .destroy() was called without error argument.

If this stream is passed as a last element in streams aray in .pipeline() method it could lead to a problem because end-of-stream won't be able to recognize that stream has been ended.

For example:

const read = new Readable({
  read() {}
});

const write = new Writable({
  emitClose: false,
  write(data, enc, cb) {
    cb();
  }
});

setImmediate(() => read.destroy());

pipeline(read, write, (err) => {
  // this never be called because `write` won't emit 'close'
});

This can be fixed by checking if this option is specified and overriding _destroy() method in order to be aware of this method has been called.

Fixes: https://github.com/nodejs/node/issues/26550

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests are included
  • commit message follows commit guidelines

Merge request reports

Loading