Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_hooks: fix AsyncLocalStorage in unhandledRejection cases #41202

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: lint
  • Loading branch information
bmeck committed Dec 20, 2021
commit 6339fba541ec24221ff800f225ec139332d7f734
25 changes: 14 additions & 11 deletions test/async-hooks/test-async-local-storage-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ const { AsyncLocalStorage } = require('async_hooks');
const vm = require('vm');

// err1 is emitted sync as a control - no events
// err2 is emitted after a timeout - uncaughtExceptionMonitor + uncaughtException
// err2 is emitted after a timeout - uncaughtExceptionMonitor
// + uncaughtException
// err3 is emitted after some awaits - unhandledRejection
// err4 is emitted during handling err3 - uncaughtExceptionMonitor
// err5 is emitted after err4 from a VM lacking hooks - unhandledRejection + uncaughtException
// err5 is emitted after err4 from a VM lacking hooks - unhandledRejection
// + uncaughtException

const asyncLocalStorage = new AsyncLocalStorage();
const callbackToken = {callbackToken:true};
const awaitToken = {awaitToken:true};
const callbackToken = { callbackToken: true };
const awaitToken = { awaitToken: true };

let i = 0;

// redefining the uncaughtExceptionHandler is a bit odd, so we just do this so we can track total invocations
// Redefining the uncaughtExceptionHandler is a bit odd, so we just do this
// so we can track total invocations
let underlyingExceptionHandler;
const exceptionHandler = common.mustCall(function(...args) {
return underlyingExceptionHandler.call(this, ...args);
Expand All @@ -31,7 +34,7 @@ const exceptionMonitor = common.mustCall((err, origin) => {
assert.strictEqual(origin, 'unhandledRejection');
assert.strictEqual(asyncLocalStorage.getStore(), awaitToken);
} else {
assert.fail('unknown error ' + err)
assert.fail('unknown error ' + err);
}
}, 2);
process.on('uncaughtExceptionMonitor', exceptionMonitor);
Expand Down Expand Up @@ -67,7 +70,7 @@ function fireErr3() {
assert.strictEqual(err.message, 'err3');
assert.strictEqual(asyncLocalStorage.getStore(), awaitToken);
process.off('unhandledRejection', rejectionHandler3);

fireErr4();
}, 1);
process.on('unhandledRejection', rejectionHandler3);
Expand All @@ -78,7 +81,7 @@ function fireErr3() {
asyncLocalStorage.run(awaitToken, awaitTest);
}

let uncaughtExceptionHandler4 = common.mustCall(
const uncaughtExceptionHandler4 = common.mustCall(
function(err) {
assert.strictEqual(err.message, 'err4');
assert.strictEqual(asyncLocalStorage.getStore(), awaitToken);
Expand All @@ -104,12 +107,12 @@ function fireErr5() {
async function main() {
await null;
Promise.resolve().then(() => {
throw new Error("err5")
})
throw new Error('err5');
});
}
main();
})})()`);
makeOrphan();
}

fireErr1();
fireErr1();
2 changes: 0 additions & 2 deletions test/parallel/test-async-wrap-pop-id-during-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ assert.strictEqual(ret.status, 0,
const stderr = ret.stderr.toString('utf8', 0, 2048);
assert.doesNotMatch(stderr, /async.*hook/i);
assert.ok(stderr.includes('Maximum call stack size exceeded'), stderr);

console.error(stdout, stderr);