Instead of filtering out promises in the async hooks added for async task tracking, add an internal path to skip adding the promise hook completely for the inspector async hook. The actual user-land promise tracking is already handled by V8 inspector. This prevents the internal promise hook from showing up and creating unnecessary noise when stepping into async execution in the inspector. PR-URL: https://github.com/nodejs/node/pull/57148 Refs: https://issues.chromium.org/issues/390581540 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
let hook;
|
|
let config;
|
|
|
|
function lazyHookCreation() {
|
|
const inspector = internalBinding('inspector');
|
|
const { createHook } = require('async_hooks');
|
|
config = internalBinding('config');
|
|
const { kNoPromiseHook } = require('internal/async_hooks');
|
|
|
|
hook = createHook({
|
|
init(asyncId, type, triggerAsyncId, resource) {
|
|
// It's difficult to tell which tasks will be recurring and which won't,
|
|
// therefore we mark all tasks as recurring. Based on the discussion
|
|
// in https://github.com/nodejs/node/pull/13870#discussion_r124515293,
|
|
// this should be fine as long as we call asyncTaskCanceled() too.
|
|
const recurring = true;
|
|
inspector.asyncTaskScheduled(type, asyncId, recurring);
|
|
},
|
|
|
|
before(asyncId) {
|
|
inspector.asyncTaskStarted(asyncId);
|
|
},
|
|
|
|
after(asyncId) {
|
|
inspector.asyncTaskFinished(asyncId);
|
|
},
|
|
|
|
destroy(asyncId) {
|
|
inspector.asyncTaskCanceled(asyncId);
|
|
},
|
|
});
|
|
hook[kNoPromiseHook] = true;
|
|
}
|
|
|
|
function enable() {
|
|
if (hook === undefined) lazyHookCreation();
|
|
if (config.bits < 64) {
|
|
// V8 Inspector stores task ids as (void*) pointers.
|
|
// async_hooks store ids as 64bit numbers.
|
|
// As a result, we cannot reliably translate async_hook ids to V8 async_task
|
|
// ids on 32bit platforms.
|
|
process.emitWarning(
|
|
'Warning: Async stack traces in debugger are not available ' +
|
|
`on ${config.bits}bit platforms. The feature is disabled.`,
|
|
{
|
|
code: 'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE',
|
|
});
|
|
} else {
|
|
hook.enable();
|
|
}
|
|
}
|
|
|
|
function disable() {
|
|
if (hook === undefined) lazyHookCreation();
|
|
hook.disable();
|
|
}
|
|
|
|
module.exports = {
|
|
enable,
|
|
disable,
|
|
};
|