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 <jasnell@gmail.com>
Fixes: #39548

PR-URL: #39550
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
jasnell authored and legendecas committed Aug 2, 2021
1 parent ba7368a commit afabd14
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 @@ -132,6 +132,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 afabd14

Please sign in to comment.