vm: memory leak on vm.compileFunction with importModuleDynamically #44211
Closed
Description
opened on Aug 11, 2022
Version
v18.6.0
Platform
Darwin
Subsystem
vm
What steps will reproduce the bug?
Run node with node --experimental-vm-modules --max-heap-size=128 test.js
, and "test.js" as:
const vm = require('vm');
function work() {
const context = vm.createContext({});
const fn = vm.compileFunction(`
import('foo').then(() => {});
`, [], {
parsingContext: context,
importModuleDynamically: async (specifier, fn, importAssertions) => {
const m = new vm.SyntheticModule(['x'], () => {
m.setExport('x', 1);
}, {
context,
});
await m.link(() => {});
await m.evaluate();
return m;
},
});
fn();
}
(function main() {
work()
// yielding to give chance to the evaluation of promises.
setTimeout(main, 1);
})();
How often does it reproduce? Is there a required condition?
always
What is the expected behavior?
Should not crash as OOM.
What do you see instead?
The program crashed with OOM shortly.
Additional information
Opening this issue to track the problem #44198 (comment).
Activity