forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: do not include partial AsyncWrap instances in heap dump
Heap dumps can be taken either through the inspector or the public API for it during an async_hooks init() hook, but at that point the AsyncWrap in question is not done initializing yet and virtual methods cannot be called on it. Address this issue (somewhat hackily) by excluding `AsyncWrap` instances which have not yet executed their `init()` hook fully from heap dumps. Fixes: nodejs#28786 PR-URL: nodejs#28789 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
Showing
5 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Flags: --expose-gc | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const v8 = require('v8'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/28786 | ||
// Make sure that creating a heap snapshot inside an async_hooks hook | ||
// works for Promises. | ||
|
||
const createSnapshot = common.mustCall(() => { | ||
v8.getHeapSnapshot().resume(); | ||
}, 8); // 2 × init + 2 × resolve + 1 × (after + before) + 2 × destroy = 8 calls | ||
|
||
const promiseIds = []; | ||
|
||
async_hooks.createHook({ | ||
init(id, type) { | ||
if (type === 'PROMISE') { | ||
createSnapshot(); | ||
promiseIds.push(id); | ||
} | ||
}, | ||
|
||
before(id) { | ||
if (promiseIds.includes(id)) createSnapshot(); | ||
}, | ||
|
||
after(id) { | ||
if (promiseIds.includes(id)) createSnapshot(); | ||
}, | ||
|
||
promiseResolve(id) { | ||
assert(promiseIds.includes(id)); | ||
createSnapshot(); | ||
}, | ||
|
||
destroy(id) { | ||
if (promiseIds.includes(id)) createSnapshot(); | ||
} | ||
}).enable(); | ||
|
||
|
||
Promise.resolve().then(() => {}); | ||
setImmediate(global.gc); |