Skip to content
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

src: fix heapSampling crash if sampleInterval is 0 #171

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/nsolid/nsolid_heap_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ int NSolidHeapSnapshot::StartSamplingProfiler(
uint64_t duration,
internal::user_data data,
Snapshot::snapshot_proxy_sig proxy) {
// Using a sampleInterval of 0 causes a v8 crash.
if (sample_interval == 0) {
return UV_EINVAL;
}

uint64_t thread_id = envinst->thread_id();
uint64_t snaphot_id =
in_progress_timers_.fetch_add(1, std::memory_order_relaxed);
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-nsolid-heap-sampling-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const nsolid = require('nsolid');
const { internalBinding } = require('internal/test/binding');

const {
UV_EINVAL,
UV_ESRCH,
} = internalBinding('uv');

Expand Down Expand Up @@ -99,6 +100,17 @@ const {
}));
}

{
// Using a sampleInterval of 0 should result in an error as it causes a crash
// on v8.
const opts = { sampleInterval: 0 };
const stream = nsolid.heapSamplingStream(0, 12000, opts);
stream.on('error', common.mustCall((err) => {
assert.strictEqual(err.message, 'Heap sampling could not be started');
assert.strictEqual(err.code, UV_EINVAL);
}));
}

{
let profile = '';
const stream = nsolid.heapSamplingStream(0, 1200);
Expand Down
Loading