mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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: https://github.com/nodejs/node/issues/44925 PR-URL: https://github.com/nodejs/node/pull/45133 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
1 parent
58bec56fab
commit
e60d9053bc
2 files changed
+22
-3
No files matched your search
@@ -262,8 +262,6 @@ function _duplexify(pair) {
|
||||
cb(err);
|
||||
} else if (err) {
|
||||
d.destroy(err);
|
||||
} else if (!readable && !writable) {
|
||||
d.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
{
|
||||
@@ -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');
|
||||
})).on('close', common.mustCall());
|
||||
}
|
||||
Reference in new issue
Block a user