Skip to content

Commit 70bd90e

Browse 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

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function eos(stream, options, callback) {
116116
returncallback.call(stream,errored);
117117
}
118118

119-
if(readable&&!readableFinished){
119+
if(readable&&!readableFinished&&isReadableNodeStream(stream,true)){
120120
if(!isReadableFinished(stream,false))
121121
returncallback.call(stream,
122122
newERR_STREAM_PREMATURE_CLOSE());

‎lib/internal/streams/utils.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ const {
99
constkDestroyed=Symbol('kDestroyed');
1010
constkIsDisturbed=Symbol('kIsDisturbed');
1111

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

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,20 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
639639
consts=newStream();
640640
finished(s,common.mustNotCall());
641641
}
642+
643+
{
644+
constserver=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)