Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a87963d

Browse filesBrowse files
debadree25juanarbol
authored andcommitted
stream: fix pipeline calling end on destination more than once
Fixes: #42866 PR-URL: #46226 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent 0defe4e commit a87963d
Copy full SHA for a87963d

File tree

Expand file treeCollapse file tree

2 files changed

+36
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+36
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/pipeline.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/pipeline.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ function pipe(src, dst, finish, { end }) {
353353
}
354354
});
355355

356-
src.pipe(dst, { end });
356+
src.pipe(dst, { end: false }); // If end is true we already will have a listener to end dst.
357357

358358
if (end) {
359359
// Compat. Before node v10.12.0 stdio used to throw an error so
Collapse file

‎test/parallel/test-stream-pipeline.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-stream-pipeline.js
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,3 +1556,38 @@ const tsp = require('timers/promises');
15561556
})
15571557
);
15581558
}
1559+
1560+
{
1561+
class CustomReadable extends Readable {
1562+
_read() {
1563+
this.push('asd');
1564+
this.push(null);
1565+
}
1566+
}
1567+
1568+
class CustomWritable extends Writable {
1569+
constructor() {
1570+
super();
1571+
this.endCount = 0;
1572+
this.str = '';
1573+
}
1574+
1575+
_write(chunk, enc, cb) {
1576+
this.str += chunk;
1577+
cb();
1578+
}
1579+
1580+
end() {
1581+
this.endCount += 1;
1582+
super.end();
1583+
}
1584+
}
1585+
1586+
const readable = new CustomReadable();
1587+
const writable = new CustomWritable();
1588+
1589+
pipeline(readable, writable, common.mustSucceed(() => {
1590+
assert.strictEqual(writable.str, 'asd');
1591+
assert.strictEqual(writable.endCount, 1);
1592+
}));
1593+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.