process: fix wrong asyncContext under unhandled-rejections=strict

Fixes: https://github.com/nodejs/node/issues/60034
PR-URL: https://github.com/nodejs/node/pull/60103
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
This commit is contained in:
Shima Ryuhei 2025-10-04 11:12:19 +09:00 committed by GitHub
parent ffb25b8ce2
commit 60f1a5d077
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 1 deletions

View File

@ -281,7 +281,7 @@ function strictUnhandledRejectionsMode(promise, promiseInfo, promiseAsyncId) {
reason : new UnhandledPromiseRejection(reason);
// This destroys the async stack, don't clear it after
triggerUncaughtException(err, true /* fromPromise */);
if (promiseAsyncId === undefined) {
if (promiseAsyncId !== undefined) {
pushAsyncContext(
promise[kAsyncIdSymbol],
promise[kTriggerAsyncIdSymbol],

View File

@ -0,0 +1,29 @@
// Flags: --unhandled-rejections=strict
'use strict';
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
process.on('unhandledRejection', common.mustNotCall);
process.on('uncaughtException', common.mustCall((err) => {
assert.ok(err.message.includes('foo'));
}));
async function readFile() {
return fs.promises.readFile(__filename);
}
async function crash() {
throw new Error('foo');
}
async function main() {
crash();
readFile();
}
main();