From a09c43c757b947d1c3f05bd9b507577914829546 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 27 Sep 2019 22:32:54 +0200 Subject: [PATCH 1/3] doc: clarify pipeline stream cleanup --- doc/api/stream.md | 6 ++++++ test.js | 9 +++++++++ 2 files changed, 15 insertions(+) create mode 100644 test.js 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); + } +}); From 4eceebab30399f83153345dab4e33b2232ef98b1 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 27 Sep 2019 22:39:00 +0200 Subject: [PATCH 2/3] fixup: ERR_STREAM_PREMATURE_CLOSE --- doc/api/stream.md | 8 +++----- test.js | 9 --------- 2 files changed, 3 insertions(+), 14 deletions(-) delete mode 100644 test.js diff --git a/doc/api/stream.md b/doc/api/stream.md index 66023b0134fd04..8d575c25a38cdc 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1590,11 +1590,9 @@ 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()` will call `stream.destroy(err)` on all streams except: +- `Readable` streams which have emitted `'end'` or `'close'`. +- `Writable` streams which have emitted `'finish'` or `'close'`. `stream.pipeline()` leaves dangling event listeners on the streams after the `callback` has been invoked. In the case of reuse of streams after diff --git a/test.js b/test.js deleted file mode 100644 index 19064b70f028fd..00000000000000 --- a/test.js +++ /dev/null @@ -1,9 +0,0 @@ -const { Readable } = require('stream') - -const r = new Readable(); - -readable.on('readable', function() { - while (data = this.read()) { - console.log(data); - } -}); From 9e896f952a77fe0afd798ebed6d65a69f681b541 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 28 Sep 2019 09:41:15 +0200 Subject: [PATCH 3/3] fixup --- doc/api/stream.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index 8d575c25a38cdc..fe8ddde4fd6b59 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1591,8 +1591,8 @@ run().catch(console.error); ``` `stream.pipeline()` will call `stream.destroy(err)` on all streams except: -- `Readable` streams which have emitted `'end'` or `'close'`. -- `Writable` streams which have emitted `'finish'` or `'close'`. +* `Readable` streams which have emitted `'end'` or `'close'`. +* `Writable` streams which have emitted `'finish'` or `'close'`. `stream.pipeline()` leaves dangling event listeners on the streams after the `callback` has been invoked. In the case of reuse of streams after