Skip to content

Commit

Permalink
stream: finished should complete with read-only Duplex
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Mathias Buus <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Juan José Arboleda <[email protected]>
  • Loading branch information
ronag authored and BethGriggs committed Apr 28, 2020
1 parent aec7bc7 commit 7647860
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
34 changes: 33 additions & 1 deletion test/parallel/test-stream-finished.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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();
}

0 comments on commit 7647860

Please sign in to comment.