diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index 35ebb39115f3be..7cd40f96cc9812 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -125,7 +125,8 @@ function handledRejection(promise) { return; } } - setHasRejectionToWarn(false); + if (maybeUnhandledPromises.size === 0 && asyncHandledRejections.length === 0) + setHasRejectionToWarn(false); } const unhandledRejectionErrName = 'UnhandledPromiseRejectionWarning'; diff --git a/test/parallel/test-promises-unhandled-rejections.js b/test/parallel/test-promises-unhandled-rejections.js index 176bae8a73ed1a..f4294800fa9dab 100644 --- a/test/parallel/test-promises-unhandled-rejections.js +++ b/test/parallel/test-promises-unhandled-rejections.js @@ -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() {}); + } +);