Skip to content

inspector: avoid calling into JS from V8 interrupts - #65028

Open
joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:fix-inspector-interrupt
Open

inspector: avoid calling into JS from V8 interrupts#65028
joyeecheung wants to merge 1 commit into
nodejs:mainfrom
joyeecheung:fix-inspector-interrupt

Conversation

@joyeecheung

@joyeecheung joyeecheung commented Aug 4, 2026

Copy link
Copy Markdown
Member

Our inspector implementation dispatches inspector messages from a V8 interrupt handler, so they could be handled during an arbitrary point of JS execution where re-calling into another irrelevant JS code is not safe.

This patch tracks V8 interrupt state in this case and rewrite the async hook toggling as state reconciliation, so requests only record the desired state, which is applied once calling into JS is possible and safe, and the actual invocation is deferred to an immediate when inside an interrupt. This simplifies the previous mechanism and makes re-entrancy and early termination safer.

Drive-by: skip installing command line API extensions during teardown when calling into JS is no longer safe.

Refs: https://issues.chromium.org/u/1/issues/42212250
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/8173727
Refs: #26935


Previously in https://issues.chromium.org/u/1/issues/42212250 V8 was open to support arbitrary JS execution in an interrupt, but that was a long time ago. In a recent CL V8 is trying to disallow arbitrary JS execution in an interrupt again, which prompted this PR to make it safer.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/inspector

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Aug 4, 2026
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.97436% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.29%. Comparing base (c8fa0b1) to head (a4b4587).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/inspector_agent.cc 54.28% 10 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65028      +/-   ##
==========================================
- Coverage   92.04%   90.29%   -1.75%     
==========================================
  Files         399      759     +360     
  Lines      175810   247628   +71818     
  Branches    27119    46679   +19560     
==========================================
+ Hits       161816   223604   +61788     
- Misses      13682    15464    +1782     
- Partials      312     8560    +8248     
Files with missing lines Coverage Δ
src/env-inl.h 95.01% <100.00%> (ø)
src/env.cc 85.21% <100.00%> (ø)
src/env.h 98.21% <ø> (ø)
src/inspector_agent.h 100.00% <ø> (ø)
src/inspector_agent.cc 80.79% <54.28%> (ø)

... and 484 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Our inspector implementation dispatches inspector messages from
a V8 interrupt handler, so they could be handled during an arbitrary
point of JS execution where re-calling into another irrelevant JS
code is not safe.

This patch tracks V8 interrupt state in this case and rewrite the
async hook toggling as state reconciliation, so requests only record
the desired state, which is applied once calling into JS is possible
and safe, and the actual invocation is deferred to an immediate when
inside an interrupt. This simplifies the previous mechanism and
makes re-entracy and early termination safer.

Drive-by: skip installing command line API extensions during
teardown when calling into JS is no longer safe.

Signed-off-by: Joyee Cheung <[email protected]>
@joyeecheung
joyeecheung force-pushed the fix-inspector-interrupt branch from bf00114 to a4b4587 Compare August 5, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants