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

inspector: no async tracking for promises #17118

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
13 changes: 12 additions & 1 deletion lib/internal/inspector_async_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,33 @@ const hook = createHook({
// 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);
if (type === 'PROMISE')
this.promises.add(asyncId);
else
inspector.asyncTaskScheduled(type, asyncId, recurring);
},

before(asyncId) {
if (this.promises.has(asyncId))
return;
inspector.asyncTaskStarted(asyncId);
},

after(asyncId) {
if (this.promises.has(asyncId))
return;
inspector.asyncTaskFinished(asyncId);
},

destroy(asyncId) {
if (this.promises.has(asyncId))
return this.promises.delete(asyncId);
inspector.asyncTaskCanceled(asyncId);
},
});

hook.promises = new Set();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know promises are properly removed from the Set when it is destroyed but from a performance standpoint would a WeakSet be more appropriate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimothyGu This stores the async ids, not the promise objects themselves … do you think I should rename this? 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh, oops. Yeah renaming would be great, although just because I made this mistake doesn’t mean any other person would.


function enable() {
if (config.bits < 64) {
// V8 Inspector stores task ids as (void*) pointers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function debuggerPausedAt(msg, functionName, previousTickLocation) {
`${Object.keys(msg.params)} contains "asyncStackTrace" property`);

assert.strictEqual(msg.params.callFrames[0].functionName, functionName);
assert.strictEqual(msg.params.asyncStackTrace.description, 'PROMISE');
assert.strictEqual(msg.params.asyncStackTrace.description, 'Promise.resolve');

const frameLocations = msg.params.asyncStackTrace.callFrames.map(
(frame) => `${frame.functionName}:${frame.lineNumber}`);
Expand Down