Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: fix duplexify premature destroy #45133

Closed
wants to merge 2 commits into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/internal/streams/duplexify.js
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
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');
}));
ronag marked this conversation as resolved.
Show resolved Hide resolved
}