Skip to content

Commit

Permalink
process: fix promise catching
Browse files Browse the repository at this point in the history
Fixes: #30953

PR-URL: #30957
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
pd4d10 authored and targos committed Dec 16, 2019
1 parent 437b6d5 commit 81e3bca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/process/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ function handledRejection(promise) {
return;
}
}
setHasRejectionToWarn(false);
if (maybeUnhandledPromises.size === 0 && asyncHandledRejections.length === 0)
setHasRejectionToWarn(false);
}

const unhandledRejectionErrName = 'UnhandledPromiseRejectionWarning';
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-promises-unhandled-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,15 @@ asyncTest(
let timer = setTimeout(common.mustNotCall(), 10000);
},
);

// https://github.com/nodejs/node/issues/30953
asyncTest(
'Catching a promise should not take effect on previous promises',
function(done) {
onUnhandledSucceed(done, function(reason, promise) {
assert.strictEqual(reason, '1');
});
Promise.reject('1');
Promise.reject('2').catch(function() {});
}
);

0 comments on commit 81e3bca

Please sign in to comment.