forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: fix the leak in SourceTextModule and ContextifySript
Replace the persistent handles to v8::Module and v8::UnboundScript with an internal reference that V8's GC is aware of to fix the leaks. PR-URL: nodejs#48510 Refs: nodejs#44211 Refs: nodejs#42080 Refs: nodejs#47096 Refs: nodejs#43205 Refs: nodejs#38695 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
- Loading branch information
1 parent
23edd1d
commit 2920904
Showing
6 changed files
with
59 additions
and
4 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,19 @@ | ||
// Flags: --max-old-space-size=16 --trace-gc | ||
'use strict'; | ||
|
||
// This tests that vm.Script with dynamic import callback does not leak. | ||
// See: https://github.com/nodejs/node/issues/33439 | ||
require('../common'); | ||
const vm = require('vm'); | ||
let count = 0; | ||
|
||
function main() { | ||
// Try to reach the maximum old space size. | ||
new vm.Script(`"${Math.random().toString().repeat(512)}";`, { | ||
async importModuleDynamically() {}, | ||
}); | ||
if (count++ < 2 * 1024) { | ||
setTimeout(main, 1); | ||
} | ||
} | ||
main(); |
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,23 @@ | ||
// Flags: --experimental-vm-modules --max-old-space-size=16 --trace-gc | ||
'use strict'; | ||
|
||
// This tests that vm.SourceTextModule() does not leak. | ||
// See: https://github.com/nodejs/node/issues/33439 | ||
require('../common'); | ||
|
||
const vm = require('vm'); | ||
let count = 0; | ||
async function createModule() { | ||
// Try to reach the maximum old space size. | ||
const m = new vm.SourceTextModule(` | ||
const bar = new Array(512).fill("----"); | ||
export { bar }; | ||
`); | ||
await m.link(() => {}); | ||
await m.evaluate(); | ||
if (count++ < 4096) { | ||
setTimeout(createModule, 1); | ||
} | ||
return m; | ||
} | ||
createModule(); |