Skip to content

Commit 403f34b

Browse files
committed
perf_hooks: fix PerformanceObserver gc crash
Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: #39548
1 parent 5ad6a99 commit 403f34b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/internal/perf/observe.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function maybeDecrementObserverCounts(entryTypes) {
130130
if (observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC &&
131131
observerCounts[observerType] === 0) {
132132
removeGarbageCollectionTracking();
133+
gcTrackingInstalled = false;
133134
}
134135
}
135136
}

test/parallel/test-perf-gc-crash.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
// Refers to https://github.com/nodejs/node/issues/39548
6+
7+
// The test fails if this crashes. If it closes normally,
8+
// then all is good.
9+
10+
const {
11+
PerformanceObserver,
12+
} = require('perf_hooks');
13+
14+
// We don't actually care if the observer callback is called here.
15+
const gcObserver = new PerformanceObserver(() => {});
16+
17+
gcObserver.observe({ entryTypes: ['gc'] });
18+
19+
gcObserver.disconnect();
20+
21+
const gcObserver2 = new PerformanceObserver(() => {});
22+
23+
gcObserver2.observe({ entryTypes: ['gc'] });
24+
25+
gcObserver2.disconnect();

0 commit comments

Comments
 (0)