Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2e05cf1

Browse filesBrowse files
joyeecheungrichardlau
authored andcommitted
module: fix leak of vm.SyntheticModule
Previously we maintain a strong persistent reference to the ModuleWrap to retrieve the ID-to-ModuleWrap mapping from the HostImportModuleDynamicallyCallback using the number ID stored in the host-defined options. As a result the ModuleWrap would be kept alive until the Environment is shut down, which would be a leak for user code. With the new symbol-based host-defined option we can just get the ModuleWrap from the JS-land WeakMap so there's now no need to maintain this strong reference. This would at least fix the leak for vm.SyntheticModule. vm.SourceTextModule is still leaking due to the strong persistent reference to the v8::Module. PR-URL: #48510 Backport-PR-URL: #51004 Refs: #44211 Refs: #42080 Refs: #47096 Refs: #43205 Refs: #38695 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
1 parent a86a2e1 commit 2e05cf1
Copy full SHA for 2e05cf1

File tree

Expand file treeCollapse file tree

2 files changed

+24
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-0
lines changed
Open diff view settings
Collapse file

‎src/module_wrap.cc‎

Copy file name to clipboardExpand all lines: src/module_wrap.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ModuleWrap::ModuleWrap(Environment* env,
6464
if (!synthetic_evaluation_step->IsUndefined()) {
6565
synthetic_ = true;
6666
}
67+
MakeWeak();
6768
}
6869

6970
ModuleWrap::~ModuleWrap() {
Collapse file
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Flags: --experimental-vm-modules --max-old-space-size=16
2+
'use strict';
3+
4+
// This tests that vm.SyntheticModule does not leak.
5+
// See https://github.com/nodejs/node/issues/44211
6+
require('../common');
7+
const vm = require('vm');
8+
9+
let count = 0;
10+
async function createModule() {
11+
// Try to reach the maximum old space size.
12+
const m = new vm.SyntheticModule(['bar'], () => {
13+
m.setExport('bar', new Array(512).fill('----'));
14+
});
15+
await m.link(() => {});
16+
await m.evaluate();
17+
if (count++ < 4 * 1024) {
18+
setTimeout(createModule, 1);
19+
}
20+
return m;
21+
}
22+
23+
createModule();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.