Skip to content

Commit 7647860

Browse files
ronagBethGriggs
authored andcommitted
stream: finished should complete with read-only Duplex
If passed a Duplex where readable or writable has been explicitly disabled then don't assume 'close' will be emitted. Fixes: #32965 PR-URL: #32967 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mathias Buus <mathiasbuus@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent aec7bc7 commit 7647860

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ function eos(stream, opts, callback) {
7676
state&&
7777
state.autoDestroy&&
7878
state.emitClose&&
79-
state.closed===false
79+
state.closed===false&&
80+
isReadable(stream)===readable&&
81+
isWritable(stream)===writable
8082
);
8183

8284
letwritableFinished=stream.writableFinished||

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
constcommon=require('../common');
4-
const{ Writable, Readable, Transform, finished }=require('stream');
4+
const{ Writable, Readable, Transform, finished, Duplex}=require('stream');
55
constassert=require('assert');
66
constEE=require('events');
77
constfs=require('fs');
@@ -352,3 +352,35 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
352352
r.push(null);
353353
r.destroy();
354354
}
355+
356+
{
357+
constd=newDuplex({
358+
final(cb){},// Never close writable side for test purpose
359+
read(){
360+
this.push(null);
361+
}
362+
});
363+
364+
d.on('end',common.mustCall());
365+
366+
finished(d,{readable: true,writable: false},common.mustCall());
367+
368+
d.end();
369+
d.resume();
370+
}
371+
372+
{
373+
constd=newDuplex({
374+
final(cb){},// Never close writable side for test purpose
375+
read(){
376+
this.push(null);
377+
}
378+
});
379+
380+
d.on('end',common.mustCall());
381+
382+
d.end();
383+
finished(d,{readable: true,writable: false},common.mustCall());
384+
385+
d.resume();
386+
}

0 commit comments

Comments
 (0)