Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in node:vm #23913

Closed
uriva opened this issue May 21, 2024 · 2 comments · Fixed by #23976
Closed

Memory leak in node:vm #23913

uriva opened this issue May 21, 2024 · 2 comments · Fixed by #23976
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@uriva
Copy link

uriva commented May 21, 2024

using this package, deno causes a memory leak where node does not

sindresorhus/get-urls#89 (comment)

import {range} from "gamla";
import getUrls from "get-urls";

for (const x of range(0, 1000)) {
  getUrls("hello");
}
console.log("all done");

deno 1.43.5 (release, x86_64-unknown-linux-gnu)
v8 12.4.254.13
typescript 5.4.5

@marvinhagemeister marvinhagemeister added bug Something isn't working correctly node compat labels May 22, 2024
@marvinhagemeister
Copy link
Contributor

Can confirm this leaks memory. It seems to be caused by something in our implementation of node:vm. I see lots of bootstrap objects in heap dumps.

@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented May 22, 2024

Smaller reproduction:

import vm from "node:vm";

const script = new vm.Script("returnValue = 2+2");

for (let i = 0; i < 1000; i++) {
  script.runInNewContext({}, { timeout: 10000 });
}

I think the leak is coming from the fact that we bootstrap and load all modules again, vs just creating a new global object.

@marvinhagemeister marvinhagemeister changed the title memory leak Memory leak in node:vm May 22, 2024
littledivy added a commit to littledivy/deno that referenced this issue May 24, 2024
We create a context in the snapshot for the VM module to reuse. This
patch fixes an oversight in the node:vm rewrite which created a new
context every time which led to high memory usage.

Fixes denoland#23913
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants