Skip to content

Commit

Permalink
stream: expect _destroy to call the callback in thennables
Browse files Browse the repository at this point in the history
Update _destroy to only call onDestroy in case of errors,
waiting for the user implementation to call onDestroy on
the success path of async functions as well.

Fixes: nodejs#40377
  • Loading branch information
TiagodePAlves committed Dec 14, 2021
1 parent 85d4cd3 commit 9c5a535
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/internal/streams/destroy.js
Expand Up @@ -19,6 +19,7 @@ const {

const kDestroy = Symbol('kDestroy');
const kConstruct = Symbol('kConstruct');
function nop() {}

function checkError(err, w, r) {
if (err) {
Expand Down Expand Up @@ -112,9 +113,7 @@ function _destroy(self, err, cb) {
if (typeof then === 'function') {
then.call(
result,
function() {
process.nextTick(onDestroy, null);
},
nop,
function(err) {
process.nextTick(onDestroy, err);
});
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-stream-construct-async-error.js
Expand Up @@ -33,6 +33,7 @@ const assert = require('assert');
async _destroy(err, cb) {
// eslint-disable-next-line no-restricted-syntax
await setTimeout(common.platformTimeout(1));
cb(err);
}
}

Expand Down

0 comments on commit 9c5a535

Please sign in to comment.