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: https://github.com/nodejs/node/issues/32965

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Robert Nagy committed 2020-04-23 19:47:11 +02:00
1 parent 50d28d4b3a
commit 4eb1701edb
2 files changed
+36 -2

No files matched your search

+3 -1
View File
@@ -76,7 +76,9 @@ function eos(stream, opts, callback) {
state &&
state.autoDestroy &&
state.emitClose &&
state.closed === false
state.closed === false &&
isReadable(stream) === readable &&
isWritable(stream) === writable
);
let writableFinished = stream.writableFinished ||
+33 -1
View File
@@ -1,7 +1,7 @@
'use strict';
const common = require('../common');
const { Writable, Readable, Transform, finished } = require('stream');
const { Writable, Readable, Transform, finished, Duplex } = require('stream');
const assert = require('assert');
const EE = require('events');
const fs = require('fs');
@@ -352,3 +352,35 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
r.push(null);
r.destroy();
}
{
const d = new Duplex({
final(cb) { }, // Never close writable side for test purpose
read() {
this.push(null);
}
});
d.on('end', common.mustCall());
finished(d, { readable: true, writable: false }, common.mustCall());
d.end();
d.resume();
}
{
const d = new Duplex({
final(cb) { }, // Never close writable side for test purpose
read() {
this.push(null);
}
});
d.on('end', common.mustCall());
d.end();
finished(d, { readable: true, writable: false }, common.mustCall());
d.resume();
}