Skip to content

Commit

Permalink
doc: clarify pipeline stream cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Sep 27, 2019
1 parent 7333c71 commit a09c43c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { Readable } = require('stream')

const r = new Readable();

readable.on('readable', function() {
while (data = this.read()) {
console.log(data);
}
});

0 comments on commit a09c43c

Please sign in to comment.