diff --git a/doc/api/stream.md b/doc/api/stream.md index bf7ee7251af392..66023b0134fd04 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1590,6 +1590,12 @@ async function run() { run().catch(console.error); ``` +On completion or error `stream.pipeline()` will call `stream.destroy(err)` on +all provided stream except for `Readable` streams which have emitted `'end'` +or `'close'` and `Writable` streams which have emitted `'finish'` or `'close'`. +Unless `autoDestroy` is enabled these streams will not be automatically cleaned +up. + `stream.pipeline()` leaves dangling event listeners on the streams after the `callback` has been invoked. In the case of reuse of streams after failure, this can cause event listener leaks and swallowed errors. diff --git a/test.js b/test.js new file mode 100644 index 00000000000000..19064b70f028fd --- /dev/null +++ b/test.js @@ -0,0 +1,9 @@ +const { Readable } = require('stream') + +const r = new Readable(); + +readable.on('readable', function() { + while (data = this.read()) { + console.log(data); + } +});