Skip to content

trace_events: fix abort when Node.js does not own the V8 platform - #65954

Open
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:fix/embedder-trace-events-no-agent
Open

trace_events: fix abort when Node.js does not own the V8 platform#65954
codebytere wants to merge 1 commit into
nodejs:mainfrom
codebytere:fix/embedder-trace-events-no-agent

Conversation

@codebytere

Copy link
Copy Markdown
Member

Requiring node:trace_events and calling createTracing() aborts the process, and getEnabledCategories() segfaults, when Node.js runs on an embedder's own platform (kNoInitializeNodeV8Platform), because no tracing::Agent exists then and lib/trace_events.js only checked the compile-time hasTracing flag and ownsProcessState before handing the null agent to the binding. Electron works around this by null-checking in node_trace_events.cc (its fix_use_embedder_perfetto_client_when_available.patch).

The binding now reports whether an agent exists and the module throws the existing ERR_TRACE_EVENTS_UNAVAILABLE when it does not, the same as a --without-v8-platform build; the error's documentation mentions the embedder case.

Tests: test/embedding/test-embedding-trace-events-unavailable.js runs createTracing() in embedtest (which uses its own platform) and expects the error code; it aborted before.

Refs: #19803


Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.

Requiring `node:trace_events` and calling `createTracing()` aborted
the process, and `getEnabledCategories()` dereferenced a null pointer,
when Node.js runs on an embedder's own platform
(`kNoInitializeNodeV8Platform`): no `tracing::Agent` exists then, and
`lib/trace_events.js` only checked the compile-time `hasTracing` flag
and `ownsProcessState` before handing the null agent to the binding.

Have the binding report whether an agent exists and throw the existing
`ERR_TRACE_EVENTS_UNAVAILABLE` when it does not, as for a
`--without-v8-platform` build.

Refs: nodejs#19803
Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. trace_events Issues and PRs related to trace events from V8, Node.js core, and user code. labels Sep 10, 2026
@codebytere codebytere added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 10, 2026
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.18%. Comparing base (b805fb5) to head (f2f8a6d).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #65954      +/-   ##
==========================================
+ Coverage   90.17%   90.18%   +0.01%     
==========================================
  Files         771      771              
  Lines      265489   265498       +9     
  Branches    50471    50475       +4     
==========================================
+ Hits       239405   239442      +37     
+ Misses      17042    16998      -44     
- Partials     9042     9058      +16     
Files with missing lines Coverage Δ
lib/trace_events.js 100.00% <100.00%> (ø)
src/node_trace_events.cc 83.05% <100.00%> (+0.74%) ⬆️

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

@codebytere codebytere removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 10, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codebytere
codebytere requested a review from anonrig September 10, 2026 12:51
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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++. needs-ci PRs that need a full CI run. trace_events Issues and PRs related to trace events from V8, Node.js core, and user code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants