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 it seems 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.

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.
@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 60.00000% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.30%. Comparing base (c8fa0b1) to head (bf00114).

Files with missing lines Patch % Lines
src/inspector_agent.cc 55.55% 10 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65028      +/-   ##
==========================================
- Coverage   92.04%   90.30%   -1.74%     
==========================================
  Files         399      759     +360     
  Lines      175810   247629   +71819     
  Branches    27119    46684   +19565     
==========================================
+ Hits       161816   223615   +61799     
- Misses      13682    15464    +1782     
- Partials      312     8550    +8238     
Files with missing lines Coverage Δ
src/env-inl.h 95.01% <100.00%> (ø)
src/env.cc 85.45% <100.00%> (ø)
src/env.h 98.21% <ø> (ø)
src/inspector_agent.h 100.00% <ø> (ø)
src/inspector_agent.cc 80.82% <55.55%> (ø)

... and 485 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.

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