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: skip promise hook in the inspector async hook #57148

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Feb 20, 2025

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.

Refs: https://issues.chromium.org/issues/390581540

Quoting myself from the DevTools issue:

From some code archeology my guess is:

  1. Node.js uses its own async hooks to call asyncTaskScheduled for all the async tasks so that they show up in the inspector Report async tasks to V8 Inspector #13870
  2. The Node.js async hooks implementation unconditionally adds Promise hooks because the API is designed in a way that allows all promises to pass through the hook (with resource type being "Promise" that allows users to filter through)
  3. The implementation in 1 does not actually need the promise hooks unconditionally set in 2. In fact it is counter-productive as Node.js needs to filter them out to avoid extra counting in the inspector inspector: no async tracking for promises #17118

I think it can probably be cleaned up by just carving out some internal path in the Node.js async hooks implementation to skip that useless promise hook.

When running node --inspect-brk await.mjs on this snippet

const test = await Promise.resolve('test')
console.log(test);

Previously, this is what you'd see in the Chrome DevTools

Screenshot 2025-02-20 at 16 05 39

After this patch

Screenshot 2025-02-20 at 16 05 55

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.
@nodejs-github-bot nodejs-github-bot added async_hooks Issues and PRs related to the async hooks subsystem. needs-ci PRs that need a full CI run. labels Feb 20, 2025
@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM modulo the lint issue

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2025
@nodejs-github-bot
Copy link
Collaborator

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.37%. Comparing base (06d5701) to head (0349af9).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57148      +/-   ##
==========================================
+ Coverage   89.02%   90.37%   +1.35%     
==========================================
  Files         665      628      -37     
  Lines      193408   184042    -9366     
  Branches    37270    35951    -1319     
==========================================
- Hits       172181   166335    -5846     
+ Misses      13888    10876    -3012     
+ Partials     7339     6831     -508     
Files with missing lines Coverage Δ
lib/async_hooks.js 99.66% <100.00%> (+<0.01%) ⬆️
lib/internal/async_hooks.js 99.36% <100.00%> (+<0.01%) ⬆️
lib/internal/inspector_async_hook.js 100.00% <100.00%> (ø)

... and 81 files with indirect coverage changes

@joyeecheung
Copy link
Member Author

Looks like I forgot to stage the symbol definition before I pushed (the undefined symbol still worked after destruction because..it will just get coerced to "undefined" and is still a valid key). Thanks @43081j for spotting it.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 20, 2025
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@legendecas legendecas added the inspector Issues and PRs related to the V8 inspector protocol label Feb 20, 2025
@legendecas
Copy link
Member

legendecas commented Feb 21, 2025

This significant improves breakpoint experience!

@joyeecheung please correct me if i'm wrong -- even though it is linked in the OP, this does not fix https://issues.chromium.org/issues/390581540 that devtools can not autocomplete in the console, right? For the autocomplete issue, there was an issue #56637 (comment) as well that V8 in Node.js assumes all devtools scripts failed side-effect check.

@joyeecheung
Copy link
Member Author

Yes, this is just an adjacent issue to the autocomplete issue in DevTools (that might interfere with debugging the actual issue, I suppose).

@GeoffreyBooth
Copy link
Member

I've been wanting this for years. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. inspector Issues and PRs related to the V8 inspector protocol needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants