Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
stream: fix duplexify premature destroy
The duplexified Duplex should be autoDestroyed instead of
prematurely destroyed when the readable and writable sides
have finished without error.

Fixes: #44925
  • Loading branch information
ronag committed Oct 23, 2022
commit a80c01337db15056db512877c6d2d744ee43f20d
2 changes: 0 additions & 2 deletions lib/internal/streams/duplexify.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ function _duplexify(pair) {
cb(err);
} else if (err) {
d.destroy(err);
} else if (!readable && !writable) {
d.destroy();
}
}

Expand Down
23 changes: 22 additions & 1 deletion test/parallel/test-stream-duplex-from.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const common = require('../common');
const assert = require('assert');
const { Duplex, Readable, Writable, pipeline } = require('stream');
const { Duplex, Readable, Writable, pipeline, PassThrough } = require('stream');
const { Blob } = require('buffer');

{
Expand Down Expand Up @@ -278,3 +278,24 @@ const { Blob } = require('buffer');

duplex.write('test');
}

{
const through = new PassThrough({ objectMode: true });

let res = '';
const d = Readable.from(['foo', 'bar'], { objectMode: true })
.pipe(Duplex.from({
writable: through,
readable: through
}));

d.on('data', (data) => {
d.pause();
setImmediate(() => {
d.resume();
});
res += data;
}).on('end', common.mustCall(() => {
assert.strictEqual(res, 'foobar');
}));
}