Skip to content

fix: prevent race condition in heap profiler - #311

Open
rohitpruthi-google wants to merge 2 commits into
google:mainfrom
rohitpruthi-google:fix-heap-profile-race-condition
Open

fix: prevent race condition in heap profiler#311
rohitpruthi-google wants to merge 2 commits into
google:mainfrom
rohitpruthi-google:fix-heap-profile-race-condition

Conversation

@rohitpruthi-google

Copy link
Copy Markdown
Contributor

This pull request fixes a race condition in the heap profiler that could cause
heap.profile() to return an empty profile if called immediately after heap.start().

The issue was that heap.profile() could be called before the V8 heap profiler had
collected any samples, resulting in a blank snapshot.

This change fixes the issue by introducing a polling mechanism in the C++ addon. The
GetAllocationProfile function now waits for the profiler to collect at least one sample
before returning a profile. This ensures that heap.profile() always returns a valid
profile.

Fixes #310

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.17%. Comparing base (dead429) to head (85d15c1).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #311      +/-   ##
==========================================
+ Coverage   41.92%   42.17%   +0.24%     
==========================================
  Files          14       14              
  Lines        2092     2101       +9     
  Branches       42       42              
==========================================
+ Hits          877      886       +9     
  Misses       1197     1197              
  Partials       18       18              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a delay is required after heap.start and heap.profile()

2 participants