Skip to content

Commit 70244d0

Browse files
ronagdanielleadams
authored andcommitted
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 PR-URL: #45133 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent 3381a17 commit 70244d0

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/internal/streams/duplexify.js

-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,6 @@ function _duplexify(pair) {
262262
cb(err);
263263
} else if (err) {
264264
d.destroy(err);
265-
} else if (!readable && !writable) {
266-
d.destroy();
267265
}
268266
}
269267

test/parallel/test-stream-duplex-from.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const common = require('../common');
44
const assert = require('assert');
5-
const { Duplex, Readable, Writable, pipeline } = require('stream');
5+
const { Duplex, Readable, Writable, pipeline, PassThrough } = require('stream');
66
const { Blob } = require('buffer');
77

88
{
@@ -278,3 +278,24 @@ const { Blob } = require('buffer');
278278

279279
duplex.write('test');
280280
}
281+
282+
{
283+
const through = new PassThrough({ objectMode: true });
284+
285+
let res = '';
286+
const d = Readable.from(['foo', 'bar'], { objectMode: true })
287+
.pipe(Duplex.from({
288+
writable: through,
289+
readable: through
290+
}));
291+
292+
d.on('data', (data) => {
293+
d.pause();
294+
setImmediate(() => {
295+
d.resume();
296+
});
297+
res += data;
298+
}).on('end', common.mustCall(() => {
299+
assert.strictEqual(res, 'foobar');
300+
})).on('close', common.mustCall());
301+
}

0 commit comments

Comments
 (0)