Skip to content

Commit

Permalink
stream: pass error on legacy destroy
Browse files Browse the repository at this point in the history
PR-URL: #43519
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
greguz authored and targos committed Jul 12, 2022
1 parent 8d14d6e commit 1617a46
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function destroyer(stream, err) {
// TODO: Don't lose err?
stream.close();
} else if (err) {
process.nextTick(emitErrorCloseLegacy, stream);
process.nextTick(emitErrorCloseLegacy, stream, err);
} else {
process.nextTick(emitCloseLegacy, stream);
}
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1526,3 +1526,33 @@ const tsp = require('timers/promises');
assert.strictEqual(val, null);
}));
}

{
// Mimics a legacy stream without the .destroy method
class LegacyWritable extends Stream {
write(chunk, encoding, callback) {
callback();
}
}

const writable = new LegacyWritable();
writable.on('error', common.mustCall((err) => {
assert.deepStrictEqual(err, new Error('stop'));
}));

pipeline(
Readable.from({
[Symbol.asyncIterator]() {
return {
next() {
return Promise.reject(new Error('stop'));
}
};
}
}),
writable,
common.mustCall((err) => {
assert.deepStrictEqual(err, new Error('stop'));
})
);
}

0 comments on commit 1617a46

Please sign in to comment.