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 70bd90e

Browse filesBrowse files
ronagtargos
authored andcommitted
stream: stricter isReadableNodeStream
Fixes: #40938 PR-URL: #40941 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 86d1c0b commit 70bd90e
Copy full SHA for 70bd90e

File tree

Expand file treeCollapse file tree

3 files changed

+23
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+23
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/end-of-stream.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/end-of-stream.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function eos(stream, options, callback) {
116116
return callback.call(stream, errored);
117117
}
118118

119-
if (readable && !readableFinished) {
119+
if (readable && !readableFinished && isReadableNodeStream(stream, true)) {
120120
if (!isReadableFinished(stream, false))
121121
return callback.call(stream,
122122
new ERR_STREAM_PREMATURE_CLOSE());
Collapse file

‎lib/internal/streams/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/utils.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ const {
99
const kDestroyed = Symbol('kDestroyed');
1010
const kIsDisturbed = Symbol('kIsDisturbed');
1111

12-
function isReadableNodeStream(obj) {
12+
function isReadableNodeStream(obj, strict = false) {
1313
return !!(
1414
obj &&
1515
typeof obj.pipe === 'function' &&
1616
typeof obj.on === 'function' &&
17+
(
18+
!strict ||
19+
(typeof obj.pause === 'function' && typeof obj.resume === 'function')
20+
) &&
1721
(!obj._writableState || obj._readableState?.readable !== false) && // Duplex
1822
(!obj._writableState || obj._readableState) // Writable has .pipe.
1923
);
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-stream-finished.js
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,20 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
639639
const s = new Stream();
640640
finished(s, common.mustNotCall());
641641
}
642+
643+
{
644+
const server = http.createServer(common.mustCall(function(req, res) {
645+
fs.createReadStream(__filename).pipe(res);
646+
finished(res, common.mustCall(function(err) {
647+
assert.strictEqual(err, undefined);
648+
}));
649+
})).listen(0, function() {
650+
http.request(
651+
{ method: 'GET', port: this.address().port },
652+
common.mustCall(function(res) {
653+
res.resume();
654+
server.close();
655+
})
656+
).end();
657+
});
658+
}

0 commit comments

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