-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: #48510 Refs: #44211 Refs: #42080 Refs: #47096 Refs: #43205 Refs: #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
4aa6b8c
commit 2dfaee4
Showing
6 changed files
with
58 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(); |