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
  • Loading branch information
ronag committed Apr 21, 2020
1 parent 8a3fa32 commit 4a3d2db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 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,8 @@ function eos(stream, opts, callback) {
state &&
state.autoDestroy &&
state.emitClose &&
state.closed === false
state.closed === false &&
(stream.readable === readable && stream.writable === writable)
);

let writableFinished = stream.writableFinished ||
Expand Down
18 changes: 17 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,19 @@ 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();
}

0 comments on commit 4a3d2db

Please sign in to comment.