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

Support specify --max-old-space-size for started server #733

Closed
singleghost opened this issue Aug 19, 2019 · 33 comments
Closed

Support specify --max-old-space-size for started server #733

singleghost opened this issue Aug 19, 2019 · 33 comments
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Milestone

Comments

@singleghost
Copy link

When I use eslint plugin in VSCode to lint a large bunch of files, the eslint server crashes. I try to find some way to add node options like "--max-old-space-size=4096", "--stack_size=10000" to start eslint server but failed.

crash message

[Info  - 5:28:05 PM] ESLint server stopped.
[Info  - 5:28:06 PM] ESLint server running in node v10.11.0
[Info  - 5:28:06 PM] ESLint server is running.
[Info  - 5:28:07 PM] ESLint library loaded from: /Users/dddong/workspace/JS2FuzzIL/node_modules/eslint/lib/api.js
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x10ae379d5 node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 2: 0x10ae37b4a node::get_builtin_module(char const*) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 3: 0x1077e2c6e v8::internal::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 4: 0x1078a3fc2 v8::internal::Heap::CreateFillerObjectAt(unsigned long, int, v8::internal::ClearRecordedSlots, v8::internal::ClearFreedMemoryMode) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 5: 0x1078a6703 v8::internal::Heap::CreateFillerObjectAt(unsigned long, int, v8::internal::ClearRecordedSlots, v8::internal::ClearFreedMemoryMode) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 6: 0x1078a272c v8::internal::Heap::CreateFillerObjectAt(unsigned long, int, v8::internal::ClearRecordedSlots, v8::internal::ClearFreedMemoryMode) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 7: 0x1078a0561 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 8: 0x1078acc75 v8::internal::Heap::RootIsImmortalImmovable(int) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
 9: 0x1078accdf v8::internal::Heap::RootIsImmortalImmovable(int) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
10: 0x107449a73 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
11: 0x107625f8c v8::internal::RegisterConfiguration::AreAliases(v8::internal::MachineRepresentation, int, v8::internal::MachineRepresentation, int) const [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]
12: 0x107a81d8e v8::internal::Parser::BuildIteratorCloseForCompletion(v8::internal::ZoneList<v8::internal::Statement*>*, v8::internal::Variable*, v8::internal::Expression*, v8::internal::IteratorType) [/Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework]

<--- Last few GCs --->

[51895:0x10c8a7000]   785803 ms: Mark-sweep 2049.1 (2086.5) -> 2048.4 (2087.5) MB, 2049.2 / 0.0 ms  (average mu = 0.073, current mu = 0.007) allocation failure scavenge might not succeed


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x107a81d8e]
Security context: 0x039f533676d9 <JSObject>
    1: /* anonymous */ [0x39f4467e3e1] [/Users/dddong/workspace/JS2FuzzIL/node_modules/acorn/dist/acorn.js:~4254] [pc=0x25db0d97b8c0](this=0x039f90bd4d69 <Parser map = 0x39fd3860a81>)
    2: /* anonymous */ [0x39f4467c2e1] [/Users/dddong/workspace/JS2FuzzIL/node_modules/acorn/dist/acorn.js:~2728] [pc=0x25db0d875615](this=0x039f90bd4d69 <Parser map = 0x39fd3860a...

Eslint version: 1.9.0
Vscode version: 1.37.0-insider

@dbaeumer
Copy link
Member

@singleghost this can currently not be controlled.

What are you linting that 1 GB of memory is not enough. The server only validates the open files so that should be usually not be more than a handful?

@dbaeumer dbaeumer added feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities labels Aug 20, 2019
@dbaeumer dbaeumer changed the title Eslint server crashes when lints a large bunch of files. Support specify --max-old-space-size for started server Aug 20, 2019
@singleghost
Copy link
Author

Actually I open hundreds of file in vscode at same time. Just because using eslint in the vscode is convenient than using it in the command line 😄 . It would be helpful If can specify the argument for starting server.

@dbaeumer
Copy link
Member

There is also a lint task in VS Code that you can use to lint all the files without the need to open them. To enable the task use eslint.lintTask.enable using 1.9.1 of ESLint. You can also control the command line using eslint.lintTask.options

@singleghost
Copy link
Author

I have tried that task but it dumps it output to the integrated terminal not the problem panel. In the problem panel, I can easily jump to the desired position in the file but I can't do this in the integrated terminal.

@dbaeumer
Copy link
Member

It does both. It dumps the output to the terminal and captures problems from it that appear in the problems view. Doesn't that work for you?

@singleghost
Copy link
Author

Oh! It does dumps the output to the problems panel. However, I still cannot pass --max-old-space-size to it because it is a node argument.

@dbaeumer
Copy link
Member

How to you pass --max-old-space-size when running eslint in the terminal ?

@singleghost
Copy link
Author

like node --max-old-space-size=8192 eslint.js

@dbaeumer
Copy link
Member

OK. Makes sense

@kelly-tock
Copy link

I get this sometimes as well if eslint is enabled and I open a directory without an eslintrc file, but am using the working directories option. I setup an ignore at the root and it seems to have helped.

@singleghost
Copy link
Author

I get this sometimes as well if eslint is enabled and I open a directory without an eslintrc file, but am using the working directories option. I setup an ignore at the root and it seems to have helped.

Yes, set a ignore would help. But I need eslint to lint large numbers of files at a time in vscode.

@kelly-tock
Copy link

Completely agree.

@maneetgoyal
Copy link

Facing a similar issue with a similar error log as given in the issue description:

Screen Shot 2019-12-20 at 9 37 09 PM

Normally, I run eslint from the command line like this: export NODE_OPTIONS=--max_old_space_size=4096 && eslint '**/*.*' --ignore-path ../../.eslintignore. Without increasing the memory usage, I get out-of-memory errors in command line also. If the server itself starts with higher allocated memory, it could solve it.

@singleghost
Copy link
Author

@maneetgoyal Totally agree!

@bradleyayers
Copy link

bradleyayers commented Jan 10, 2020

I hit this problem constantly, and I believe it's because I use typescript-eslint which uses quite a lot of memory to gather type information for the project (as it needs to compile the whole project). Is microsoft/vscode-languageserver-node#467 something you'd like to fix and rely on for this issue? What approach would you recommend for implementing this?

@bradleyayers
Copy link

I've ended up using the eslint.runtime option for this, with the script:

#!/bin/bash

echo "ESLint server using Node.js from: $0"
export NODE_OPTIONS=--max_old_space_size=4096
echo "ESLint server using NODE_OPTIONS: $NODE_OPTIONS"
node $@

@singleghost
Copy link
Author

I've ended up using the eslint.runtime option for this, with the script:

#!/bin/bash

echo "ESLint server using Node.js from: $0"
export NODE_OPTIONS=--max_old_space_size=4096
echo "ESLint server using NODE_OPTIONS: $NODE_OPTIONS"
node $@

It is a nice approach to work around this.

@maneetgoyal
Copy link

maneetgoyal commented Mar 4, 2020

I've ended up using the eslint.runtime option for this, with the script:

#!/bin/bash

echo "ESLint server using Node.js from: $0"
export NODE_OPTIONS=--max_old_space_size=4096
echo "ESLint server using NODE_OPTIONS: $NODE_OPTIONS"
node $@

@bradleyayers @singleghost Can you please add some more details? I think I'm doing something wrong. Currently, I have this in my settings.json: "eslint.runtime": "./vscode-eslint.sh", and vscode-eslint.sh contains the code you suggested. Getting the following error:

Screen Shot 2020-03-03 at 6 34 21 PM


Using absolute path for the bash script seemed to work, after chmod.

@dbaeumer dbaeumer added this to the Backlog milestone Mar 4, 2020
@kelly-tock
Copy link

with this approach, I can't seem to get it to use the node version that the project is using. I tried setting vscode eslint runtime, setting default node version for nvm, opening code through command line. anyone able to get this to use the node version you want?

@kelly-tock
Copy link

ok, update, if I nvm alias default 13.13.0, then open code from command line, this seems to be working to use the node I want.

@ghost ghost mentioned this issue Jan 8, 2021
@akowi-sknobloch
Copy link

I have big trouble with this problem.
Tried @bradleyayers workaround with --max_old_space_size=8192 and it still runs out of memory!
Tried around some stuff i found to optimize the eslintrc with no luck.
I have a midsize Project containing a NestJs Server + Client with a total of ~ 100 Typescript files.

@dbaeumer
Copy link
Member

dbaeumer commented Oct 1, 2021

Added setting eslint.runtime.execArgv

@dbaeumer dbaeumer modified the milestones: Backlog, 2.2.0 Oct 1, 2021
@bradtaniguchi
Copy link

For anyone confused as to why eslint.runtime.execArgv isn't recognized, as of 2.2.2, the setting was changed to:
eslint.execArgv

See:
https://github.com/microsoft/vscode-eslint/blob/main/CHANGELOG.md#222

@castrix
Copy link

castrix commented Sep 22, 2022

For anyone confused as to why eslint.runtime.execArgv isn't recognized, as of 2.2.2, the setting was changed to:
eslint.execArgv

Hi @bradleyayers @dbaeumer , is there any documentation on how I can use eslint.execArgv?

@dbaeumer
Copy link
Member

They are the same as normal node command line options.

@castrix
Copy link

castrix commented Sep 27, 2022

thanks for the answer @dbaeumer
but I got this message when I tried to configure it for wsl

This setting cannot be applied in this window. It will be applied when you open a local window.

image

@castrix
Copy link

castrix commented Sep 27, 2022

Nevermind, I configured the wrong settings.json file, wsl has different settings.json file

@vlad2135
Copy link

vlad2135 commented Feb 24, 2023

Why does this feature not help me? Process explorer shows that eslint server is started by anover code process, which reads eslint.execArgv parameter and command line looks like this:
"C:\Program Files\Microsoft VS Code\Code.exe" --ms-enable-electron-run-as-node --max_old_space_size=8192 c:\Users\itsamemario\.vscode\extensions\dbaeumer.vscode-eslint-2.4.0\server\out\eslintServer.js --node-ipc --clientProcessId=28252

but still VSCode ESLint OUTPUT shows OOM exceptions at 4Gb bounday:
<--- Last few GCs --->

[3344:000015FA002EC000] 180755 ms: Scavenge 3960.5 (4058.1) -> 3960.3 (4058.1) MB, 55.6 / 0.0 ms (average mu = 0.881, current mu = 0.581) allocation failure;
[3344:000015FA002EC000] 180820 ms: Scavenge 3960.4 (4058.1) -> 3960.4 (4058.1) MB, 62.8 / 0.0 ms (average mu = 0.881, current mu = 0.581) allocation failure;
[3344:000015FA002EC000] 180887 ms: Scavenge 3960.4 (4058.1) -> 3960.4 (4058.1) MB, 66.5 / 0.0 ms (average mu = 0.881, current mu = 0.581) allocation failure;

<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory

@scamden
Copy link

scamden commented Mar 10, 2023

@vlad2135 same here! just verified process should have the arg:

/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=8192 /Users/scamden/.vscode/extensions/dbaeumer.vscode-eslint-2.4.0/server/out/eslintServer.js --node-ipc --clientProcessId=61748

but running out of memory right at 4gb still!

@dbaeumer any ideas? the setting is

"eslint.execArgv": ["--max-old-space-size=8192"],

@dbaeumer
Copy link
Member

Actually now. Have you tried with a pure node runtime (e.g. using eslint.runtime setting)

@scamden
Copy link

scamden commented Mar 10, 2023

fyi i believe it's this: https://stackoverflow.com/questions/69581598/after-upgrading-electron-from-1-to-10-the-max-old-space-size-command-cant-se

i confirmed that setting this to 1024 is reflected (and crashes very quickly lol). So the max at 4g seems to be this pointer compression thing. Enabling a pure node runtime seems like it will allow more than 4gb but without pointer compression will also take a bunch of extra ram (like 6gb instead of 4gb)

@dbaeumer
Copy link
Member

@scamden thanks for the pointer. I wasn't aware of that. So the recommendation is to use a pure node runtime if you need a larger heap.

@vlad2135
Copy link

Actually now. Have you tried with a pure node runtime (e.g. using eslint.runtime setting)

Thank you for the advice, it worked!
In combination with eslint.execArgv it spawns a separate node process which allocates > 4Gb memory. I've tested with 8Gb and plugin still crashes on our codebase :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

10 participants