Skip to content

Commit 016b7ba

Browse files
jasnelldanielleadams
authored andcommitted
perf_hooks: fix PerformanceObserver gc crash
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>
1 parent 635e1a0 commit 016b7ba

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
@@ -132,6 +132,7 @@ function maybeDecrementObserverCounts(entryTypes) {
132132
if (observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC &&
133133
observerCounts[observerType] === 0) {
134134
removeGarbageCollectionTracking();
135+
gcTrackingInstalled = false;
135136
}
136137
}
137138
}
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)