diff --git a/lib/internal/process/promises.js b/lib/internal/process/promises.js index ab833776070449..47d58de99611fe 100644 --- a/lib/internal/process/promises.js +++ b/lib/internal/process/promises.js @@ -123,7 +123,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() {}); + } +);