diff options
author | Debadree Chatterjee <debadree333@gmail.com> | 2023-04-27 13:14:39 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-27 07:44:39 +0000 |
commit | f34a07d3a78fe34e6221c42721ae3f2f6a3d8cf0 (patch) | |
tree | 5d9dc30199363c918d09e2a2cb81c8e8fd76ae4e | |
parent | b6738c1af040505bcb241b8740eb91e81c15eb44 (diff) | |
download | node-new-f34a07d3a78fe34e6221c42721ae3f2f6a3d8cf0.tar.gz |
stream: prevent pipeline hang with generator functions
Fixes: https://github.com/nodejs/node/issues/47708
PR-URL: https://github.com/nodejs/node/pull/47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
-rw-r--r-- | lib/internal/streams/pipeline.js | 3 | ||||
-rw-r--r-- | test/parallel/test-stream-pipeline.js | 18 |
2 files changed, 19 insertions, 2 deletions
diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 95737d95e4..062bdc192d 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -138,10 +138,9 @@ async function pumpToNode(iterable, writable, finish, { end }) { if (end) { writable.end(); + await wait(); } - await wait(); - finish(); } catch (err) { finish(error !== err ? aggregateTwoErrors(error, err) : err); diff --git a/test/parallel/test-stream-pipeline.js b/test/parallel/test-stream-pipeline.js index d37ca275f1..e9f6a2fdf7 100644 --- a/test/parallel/test-stream-pipeline.js +++ b/test/parallel/test-stream-pipeline.js @@ -1616,3 +1616,21 @@ const tsp = require('timers/promises'); dup.push(null); dup.read(); } + +{ + let res = ''; + const writable = new Writable({ + write(chunk, enc, cb) { + res += chunk; + cb(); + } + }); + pipelinep(async function*() { + yield 'hello'; + await Promise.resolve(); + yield 'world'; + }, writable, { end: false }).then(common.mustCall(() => { + assert.strictEqual(res, 'helloworld'); + assert.strictEqual(writable.closed, false); + })); +} |