mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
perf_hooks: fix PerformanceObserver 'gc' crash
Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: https://github.com/nodejs/node/issues/38412 PR-URL: https://github.com/nodejs/node/pull/38414 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
This commit is contained in:
1 parent
4f6c4eb144
commit
013fa59602
2 files changed
+23
-1
No files matched your search
@@ -72,6 +72,8 @@ const kDeprecationMessage =
|
||||
const kTypeSingle = 0;
|
||||
const kTypeMultiple = 1;
|
||||
|
||||
let gcTrackingInstalled = false;
|
||||
|
||||
const kSupportedEntryTypes = ObjectFreeze([
|
||||
'function',
|
||||
'gc',
|
||||
@@ -124,8 +126,11 @@ function maybeIncrementObserverCount(type) {
|
||||
|
||||
if (observerType !== undefined) {
|
||||
observerCounts[observerType]++;
|
||||
if (observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC)
|
||||
if (!gcTrackingInstalled &&
|
||||
observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC) {
|
||||
installGarbageCollectionTracking();
|
||||
gcTrackingInstalled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
require('../common');
|
||||
|
||||
// Verifies that setting up two observers to listen
|
||||
// to gc performance does not crash.
|
||||
|
||||
const {
|
||||
PerformanceObserver,
|
||||
} = require('perf_hooks');
|
||||
|
||||
// We don't actually care if the callback is ever invoked in this test
|
||||
const obs = new PerformanceObserver(() => {});
|
||||
const obs2 = new PerformanceObserver(() => {});
|
||||
|
||||
obs.observe({ type: 'gc' });
|
||||
obs2.observe({ type: 'gc' });
|
||||
Reference in new issue
Block a user