Skip to content

Commit 4a3d2db

Browse files
committedApr 21, 2020
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: nodejs#32965
1 parent 8a3fa32 commit 4a3d2db

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ function eos(stream, opts, callback) {
7676
state &&
7777
state.autoDestroy &&
7878
state.emitClose &&
79-
state.closed === false
79+
state.closed === false &&
80+
(stream.readable === readable && stream.writable === writable)
8081
);
8182

8283
let writableFinished = stream.writableFinished ||

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const common = require('../common');
4-
const { Writable, Readable, Transform, finished } = require('stream');
4+
const { Writable, Readable, Transform, finished, Duplex } = require('stream');
55
const assert = require('assert');
66
const EE = require('events');
77
const fs = require('fs');
@@ -352,3 +352,19 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
352352
r.push(null);
353353
r.destroy();
354354
}
355+
356+
{
357+
const d = new Duplex({
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+
}

0 commit comments

Comments
 (0)
Please sign in to comment.