Skip to content

Commit

Permalink
perf_hooks: fix PerformanceObserver gc crash
Browse files Browse the repository at this point in the history
Signed-off-by: James M Snell <[email protected]>
Fixes: #39548
  • Loading branch information
jasnell committed Jul 27, 2021
1 parent 5ad6a99 commit 403f34b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/internal/perf/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function maybeDecrementObserverCounts(entryTypes) {
if (observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC &&
observerCounts[observerType] === 0) {
removeGarbageCollectionTracking();
gcTrackingInstalled = false;
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-perf-gc-crash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

require('../common');

// Refers to https://github.com/nodejs/node/issues/39548

// The test fails if this crashes. If it closes normally,
// then all is good.

const {
PerformanceObserver,
} = require('perf_hooks');

// We don't actually care if the observer callback is called here.
const gcObserver = new PerformanceObserver(() => {});

gcObserver.observe({ entryTypes: ['gc'] });

gcObserver.disconnect();

const gcObserver2 = new PerformanceObserver(() => {});

gcObserver2.observe({ entryTypes: ['gc'] });

gcObserver2.disconnect();

0 comments on commit 403f34b

Please sign in to comment.