GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf_hooks: fix PerformanceObserver 'gc' crash · nodejs/node@013fa59

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/perf
    • observe.js
  • test/parallel
    • test-performanceobserver-gc.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/perf/observe.js‎

Copy file name to clipboardExpand all lines: lib/internal/perf/observe.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const kDeprecationMessage =
7272
const kTypeSingle = 0;
7373
const kTypeMultiple = 1;
7474

75+
let gcTrackingInstalled = false;
76+
7577
const kSupportedEntryTypes = ObjectFreeze([
7678
'function',
7779
'gc',
@@ -124,8 +126,11 @@ function maybeIncrementObserverCount(type) {
124126

125127
if (observerType !== undefined) {
126128
observerCounts[observerType]++;
127-
if (observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC)
129+
if (!gcTrackingInstalled &&
130+
observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC) {
128131
installGarbageCollectionTracking();
132+
gcTrackingInstalled = true;
133+
}
129134
}
130135
}
131136

Collapse file

‎test/parallel/test-performanceobserver-gc.js‎

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
// Verifies that setting up two observers to listen
6+
// to gc performance does not crash.
7+
8+
const {
9+
PerformanceObserver,
10+
} = require('perf_hooks');
11+
12+
// We don't actually care if the callback is ever invoked in this test
13+
const obs = new PerformanceObserver(() => {});
14+
const obs2 = new PerformanceObserver(() => {});
15+
16+
obs.observe({ type: 'gc' });
17+
obs2.observe({ type: 'gc' });

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.