trace_events: fix abort when Node.js does not own the V8 platform - #65954
Open
codebytere wants to merge 1 commit into
Open
trace_events: fix abort when Node.js does not own the V8 platform#65954codebytere wants to merge 1 commit into
codebytere wants to merge 1 commit into
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
Collaborator
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requiring
node:trace_eventsand callingcreateTracing()aborts the process, andgetEnabledCategories()segfaults, when Node.js runs on an embedder's own platform (kNoInitializeNodeV8Platform), because notracing::Agentexists then andlib/trace_events.jsonly checked the compile-timehasTracingflag andownsProcessStatebefore handing the null agent to the binding. Electron works around this by null-checking innode_trace_events.cc(itsfix_use_embedder_perfetto_client_when_available.patch).The binding now reports whether an agent exists and the module throws the existing
ERR_TRACE_EVENTS_UNAVAILABLEwhen it does not, the same as a--without-v8-platformbuild; the error's documentation mentions the embedder case.Tests:
test/embedding/test-embedding-trace-events-unavailable.jsrunscreateTracing()inembedtest(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.