forked from google/pprof-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 8
fix(heap): don't assume a per-isolate state exists #384
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
Merged
+207
−19
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5de4dba
fix(heap): don't assume a per-isolate state exists
szegedi 82f5a8b
test(heap): keep the forked child out of LeakSanitizer's reach
szegedi 0ede06e
fix(heap): guard NearHeapLimit's profile, drop its bogus state check
szegedi b7ba01c
fix(heap): uninstall the near-heap-limit callback before dropping the…
szegedi 85f19f4
fix(heap): re-add NearHeapLimit's null-state guard, with a real reason
szegedi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Copyright 2026 Datadog, Inc | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // Runs in a forked process because the failure mode under test is a SIGSEGV, | ||
| // which would take the whole mocha run down with it. | ||
| // | ||
| // V8's sampling heap profiler can be enabled by anything in the process - here | ||
| // the inspector's HeapProfiler.startSampling, but equally DevTools or another | ||
| // agent. That leaves getAllocationProfile()/mapAllocationProfile() with a live | ||
| // V8 profile but no per-isolate HeapProfilerState, since only | ||
| // startSamplingHeapProfiler() creates one. Both used to dereference that empty | ||
| // shared_ptr. | ||
|
|
||
| import * as inspector from 'inspector'; | ||
|
|
||
| import * as v8HeapProfiler from '../src/heap-profiler-bindings'; | ||
|
|
||
| function post( | ||
| session: inspector.Session, | ||
| method: string, | ||
| params?: object, | ||
| ): Promise<void> { | ||
| return new Promise((resolve, reject) => { | ||
| session.post(method, params, err => (err ? reject(err) : resolve())); | ||
| }); | ||
| } | ||
|
|
||
| async function main() { | ||
| const session = new inspector.Session(); | ||
| session.connect(); | ||
|
|
||
| await post(session, 'HeapProfiler.enable'); | ||
| await post(session, 'HeapProfiler.startSampling', {samplingInterval: 16384}); | ||
|
|
||
| // Allocate so the sampler actually has samples to report. Kept modest and | ||
| // scoped to this function: the profile only needs a non-empty sample set. | ||
| const retained: Array<{i: number; s: string}> = []; | ||
| for (let i = 0; i < 20000; i++) { | ||
| retained.push({i, s: 'x'.repeat(16)}); | ||
| } | ||
|
|
||
| // pprof never started the heap profiler, so there is no state for this | ||
| // isolate. Both of these must return rather than crash. | ||
| const profile = v8HeapProfiler.getAllocationProfile(); | ||
| if (!profile || typeof profile.name !== 'string') { | ||
| throw new Error('getAllocationProfile returned an unusable profile'); | ||
| } | ||
|
|
||
| const mapped = v8HeapProfiler.mapAllocationProfile(node => node.name); | ||
| if (typeof mapped !== 'string') { | ||
| throw new Error('mapAllocationProfile did not invoke the callback'); | ||
| } | ||
|
|
||
| await post(session, 'HeapProfiler.stopSampling'); | ||
| session.disconnect(); | ||
| } | ||
|
|
||
| main().then( | ||
| () => process.exit(0), | ||
| err => { | ||
| console.error(err); | ||
| process.exit(1); | ||
| }, | ||
| ); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: keep
state->profile.reset();, it should not hurt