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

JavaScript heap out of memory Alpine Linux #1268

Open
songp-pi opened this issue Feb 2, 2023 · 1 comment
Open

JavaScript heap out of memory Alpine Linux #1268

songp-pi opened this issue Feb 2, 2023 · 1 comment

Comments

@songp-pi
Copy link

songp-pi commented Feb 2, 2023

Describe the bug
JavaScript heap out of memory
Screenshot 2023-02-02 at 17 31 21

Versions:

  • Chokidar version 3.5.3
  • Node version v16.15.1
  • OS version: Alpine Linux 3.14

To Reproduce:

I create 250000 files in FILE_DIR and get the memory leak, this code just log the messages
And the memory growth over time when create more files

const test = () => {
  const watcher = chokidar.watch([
    FILE_DIR
  ], {
    awaitWriteFinish: true,
    ignored: [
      `${FILE_DIR}/*.txt`,
    ],
    persistent: true,
    ignoreInitial: true,
    usePolling: true,
  });
  watcher
    .on('all', (event, path) => {
      console.log(`File ${path} has been ${event}`);
    })
}
test();
@patricknelson
Copy link

patricknelson commented Mar 8, 2024

Found that this occurs even with a much smaller number of files, particularly if a large set of them happen to change all at once (e.g. ~180 or so in my case, all of them .css and .map files in only like 4 subdirectories, including the root one). That said, I found that removing the nested css/**/*.css glob pattern alleviates the issue. Give that a shot.

You can test this by checking memory usage live as it's running. I do this by running the script in debug mode via:

NODE_OPTIONS='--inspect' node test.js

Then open Chrome DevTools, click the Node.js logo that comes up and then open the "Memory" tab. There you'll see this below. For me, it always starts out at 5MB. However, with the nested subdirectory glob pattern **/ it will bloat until the VM runs out of memory (>2GB). But if I just explicitly watch *.css in each of the 4 explicit directories, it bloats to maybe 150MB at most, hovers around 70MB but eventually falls back to like 5MB.

image


Edit: #1271 does a fantastic breakdown and I think that's actually what is happening here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants