process: emit unhandled warning immediately
PR-URL: https://github.com/nodejs/node/pull/24632 Fixes: https://github.com/nodejs/node/issues/24209 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
parent
b5c5d206af
commit
3ce9305a70
@ -108,7 +108,7 @@ function emitPromiseRejectionWarnings() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let hadListeners = false;
|
let maybeScheduledTicks = false;
|
||||||
let len = pendingUnhandledRejections.length;
|
let len = pendingUnhandledRejections.length;
|
||||||
while (len--) {
|
while (len--) {
|
||||||
const promise = pendingUnhandledRejections.shift();
|
const promise = pendingUnhandledRejections.shift();
|
||||||
@ -118,10 +118,9 @@ function emitPromiseRejectionWarnings() {
|
|||||||
const { reason, uid } = promiseInfo;
|
const { reason, uid } = promiseInfo;
|
||||||
if (!process.emit('unhandledRejection', reason, promise)) {
|
if (!process.emit('unhandledRejection', reason, promise)) {
|
||||||
emitWarning(uid, reason);
|
emitWarning(uid, reason);
|
||||||
} else {
|
|
||||||
hadListeners = true;
|
|
||||||
}
|
}
|
||||||
|
maybeScheduledTicks = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hadListeners || pendingUnhandledRejections.length !== 0;
|
return maybeScheduledTicks || pendingUnhandledRejections.length !== 0;
|
||||||
}
|
}
|
||||||
|
@ -699,3 +699,22 @@ asyncTest('Rejected promise inside unhandledRejection allows nextTick loop' +
|
|||||||
process.nextTick(() => promise.catch(() => done()));
|
process.nextTick(() => promise.catch(() => done()));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
asyncTest(
|
||||||
|
'Unhandled promise rejection emits a warning immediately',
|
||||||
|
function(done) {
|
||||||
|
clean();
|
||||||
|
Promise.reject(0);
|
||||||
|
const { emitWarning } = process;
|
||||||
|
process.emitWarning = common.mustCall((...args) => {
|
||||||
|
if (timer) {
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = null;
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
emitWarning(...args);
|
||||||
|
}, 2);
|
||||||
|
|
||||||
|
let timer = setTimeout(common.mustNotCall(), 10000);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user