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 used by background process increases endlessly. #264

Open
mteplyi opened this issue Oct 2, 2023 · 5 comments
Open

Memory used by background process increases endlessly. #264

mteplyi opened this issue Oct 2, 2023 · 5 comments

Comments

@mteplyi
Copy link

mteplyi commented Oct 2, 2023

Hi, it is awesome project, but I noticed probably a memory leak. If server is already running, I change any file from check_files array (package.json, package-lock.json, npm-shrinkwrap.json, yarn.lock, pnpm-lock.yaml) and run eslint_d again, then the memory used by background eslint_d process increases for about 100-200 MB. It repeats over and over again. For me it reached even 3 GB and then I have to restart it manually.
I run eslint_d for the first time and every next time with the same command and only in one project:
eslint_d --cache --fix **/*.ts
I have spent a lot of time trying to manage this issue in source code, but I can not understand where exactly it happens.
Can someone help with it?

@mteplyi
Copy link
Author

mteplyi commented Oct 2, 2023

Seems like a lot of stuff was not deleted from memory on clear before new cache creation. I tried to analyze a heap and can assume, that it hangs somewhere in ESLint class and so deletion of require.cache and lru entries does not kill all refs. Maybe, it will be simpler to just restart background eslint_d process on those check_files changes..

And also it would be great to have an ability to pass such check_files through cli args.

@hinell
Copy link

hinell commented Oct 30, 2023

image

The same issue if run over a directory of files without --cache flag. With --cache it doesn't take more than 200mb of RAM. Probably worth to enable this flag by default.

To reproduce, clone this repo: AykutSarac/jsoncrack.com

eslint_d ./
❯  eslint_d -v
v8.52.0 (eslint_d v13.0.0)

UPD: The issue is rather occasional

@frixaco
Copy link

frixaco commented Nov 12, 2023

Can confirm. I'm getting over 1.2GB of memory usage

@mantoni
Copy link
Owner

mantoni commented Nov 13, 2023

My best guess is that you have plugins that use import instead of require. While eslint_d clears the require cache, there is no solution for modules in place:

function clearRequireCache(cwd) {
Object.keys(require.cache)
.filter(key => key.startsWith(cwd))
.forEach((key) => {
delete require.cache[key];
});
}

Does anyone knows if/how imported modules can be cleared? Would we need a custom loader?

An alternative would be to change the architecture of eslint_d and launch a separate process for each project (cwd). When reloading the project, we could dispose the process and re-create it. Any thoughts?

@Amar-Gill
Copy link

Screenshot 2024-01-05 at 2 34 52 PM

I'm using Neovim and I set up eslint_d through Mason: https://github.com/williamboman/mason.nvim

Sitting at 4GB memory consumption. And I have no instance of nvim open currently.

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

5 participants