microsoft / vscode-eslint

VSCode extension to integrate eslint into VSCode
MIT License
1.73k stars 334 forks source link

Have to reload window often #1156

Closed ghost closed 2 years ago

ghost commented 3 years ago

We've recently switched from TSLint to ESLint in a large mono repo. After a while, about every 10-30 minutes, ESLint stops working and I have to reload the VSCode window. It will then no longer show new issues, and when I click CTRL + . on an issue it found before the crash, it shows "No code actions available".

When I check the Output console, I see these errors all the time:

(node:14432) UnhandledPromiseRejectionWarning: Error: Unhandled method eslint/confirmESLintExecution
    at c:\Users\r_old\.vscode\extensions\dbaeumer.vscode-eslint-2.1.14\server\out\eslintServer.js:1:53829
    at c:\Users\r_old\.vscode\extensions\dbaeumer.vscode-eslint-2.1.14\server\out\eslintServer.js:1:54123
    at Immediate.<anonymous> (c:\Users\r_old\.vscode\extensions\dbaeumer.vscode-eslint-2.1.14\server\out\eslintServer.js:1:54488)
    at processImmediate (internal/timers.js:439:21)
(node:14432) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14432) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Once it has crashed, and I try to do CTRL + . for the code actions, I see this in the output console:

[Error - 1:08:53 PM] Request textDocument/codeAction failed.
  Message: Unhandled method eslint/confirmESLintExecution
  Code: -32601 

It just crashed again, at the time it happened this was in the logs:

<--- Last few GCs --->

[26272:0000014600000000]   597028 ms: Scavenge 3793.3 (3815.5) -> 3788.0 (3817.0) MB, 5.3 / 0.0 ms  (average mu = 0.936, current mu = 0.863) allocation failure 
[26272:0000014600000000]   597060 ms: Scavenge 3794.6 (3817.0) -> 3789.4 (3818.2) MB, 5.2 / 0.0 ms  (average mu = 0.936, current mu = 0.863) allocation failure 
[26272:0000014600000000]   597110 ms: Scavenge 3796.5 (3818.8) -> 3791.2 (3818.8) MB, 10.9 / 0.0 ms  (average mu = 0.936, current mu = 0.863) allocation failure 

<--- JS stacktrace --->

FATAL ERROR: NewSpace::Rebalance Allocation failed - JavaScript heap out of memory
 1: 00007FF76538B4CA VR_GetStringForHmdError+219210
 2: 00007FF7649187B6 node::Buffer::New+43430
 3: 00007FF764918823 node::Buffer::New+43539
 4: 00007FF763421048 v8::internal::Version::GetVersion+792
 5: 00007FF763420FF1 v8::internal::Version::GetVersion+705
 6: 00007FF7635AC203 v8::Unlocker::~Unlocker+254307
 7: 00007FF7635D5321 v8::Unlocker::~Unlocker+422529
 8: 00007FF7635D21C9 v8::Unlocker::~Unlocker+409897
 9: 00007FF7635AC3FC v8::Unlocker::~Unlocker+254812
10: 00007FF7635A9958 v8::Unlocker::~Unlocker+243896
11: 00007FF7635A79AD v8::Unlocker::~Unlocker+235789
12: 00007FF7635B2D76 v8::Unlocker::~Unlocker+281814
13: 00007FF7635B2E5D v8::Unlocker::~Unlocker+282045
14: 00007FF763588242 v8::Unlocker::~Unlocker+106914
15: 00007FF7638A3899 v8::internal::TickSample::print+352969
16: 00007FF763DCDF7C v8_inspector::V8StackTraceId::ToString+2983916
17: 000001460038709F 
[Info  - 1:21:45 PM] Connection to server got closed. Server will restart.
[Info  - 1:21:45 PM] ESLint server stopped.
[Info  - 1:21:45 PM] ESLint server is starting
[Info  - 1:21:45 PM] ESLint server running in node v12.14.1
[Info  - 1:21:45 PM] ESLint server is running.
(node:21356) UnhandledPromiseRejectionWarning: Error: Unhandled method eslint/confirmESLintExecution
    at c:\Users\r_old\.vscode\extensions\dbaeumer.vscode-eslint-2.1.14\server\out\eslintServer.js:1:53829
    at c:\Users\r_old\.vscode\extensions\dbaeumer.vscode-eslint-2.1.14\server\out\eslintServer.js:1:54123
    at Immediate.<anonymous> (c:\Users\r_old\.vscode\extensions\dbaeumer.vscode-eslint-2.1.14\server\out\eslintServer.js:1:54488)
    at processImmediate (internal/timers.js:439:21)

I can't find any existing issue about it.

I'm on Node 12.14.1 and ESLint 2.1.14

dbaeumer commented 3 years ago

It looks like the ESLint server is running out of memory. You could use the eslint.runtime setting to point to a script that starts node with --max_old_space_size set yo a higher value.

What is suspicious is the fact that restarting the server doesn't correctly register a confirmESLintExecution handler. Will look into why this is happening.

ghost commented 3 years ago

Thanks @dbaeumer , yes if the restart would work properly then it's better. I see there's a lengthy discussion on the Typescript eslint repo about the high memory usage: https://github.com/typescript-eslint/typescript-eslint/issues/1192

I tried using the runtime setting but keep getting Launching server using runtime ./vscode-eslint.sh failed despite the file being there. I'm on Windows, the rest of my team is on MacOS and Linux so I'm also worried about cross platform issues. See issue: https://github.com/microsoft/vscode-eslint/issues/733

Ideally there's a way to configure the node command line arguments, e.g. eslint.node-args or something.

dbaeumer commented 3 years ago

I agree on the possibility to configure that as a eslint setting. PR welcome.

Regarding the shell script. That will not work on Windows since there it will try to use cmd.exe. Does it work for your team mates using Mac?

kzimny commented 3 years ago

I had exactly the same issue. None of the solutions I found in similar issues worked on my Windows environment. The only one which work is to set "eslint.runtime": "node" without passing --max_old_space_size=4096 option. The settings.json file looks as follow:

{
    "files.exclude": {
        "**/*.js": {
            "when": "$(basename).ts"
        },
        "**/*.map": {
            "when": "$(basename).map"
        },
        "hooks": true,
        "platforms": true,
        "node_modules": true
    },
    "typescript.updateImportsOnFileMove.enabled": "always",
    "nativescript.analytics.enabled": false,
    "javascript.updateImportsOnFileMove.enabled": "always",
    "workbench.activityBar.visible": true,
    "window.zoomLevel": 0,
    "[html]": {
        "editor.defaultFormatter": "vscode.html-language-features"
    },
    "git.showPushSuccessNotification": true,
    "scm.alwaysShowRepositories": true,
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "diffEditor.ignoreTrimWhitespace": false,
    "eslint.alwaysShowStatus": true,
    "eslint.validate": [
        "javascript", 
        "html",
        "typescript"
    ],
    "eslint.runtime": "node"
}

It works fine in monorepo project with four angular, cordova and electron projects in the same workspace with over 1'200 ts files.

JaLe29 commented 3 years ago

Tip:

Try to update your .eslintignore.

You must put node_modules folder to your .eslintignore to prevent eslint analys scan over this huge folder.

ranisalt commented 3 years ago

Putting node_modules into .eslintignore does not help, eslint server crashes in the first run always. It started happening after updating to 2.1.14, it was not so often with 2.1.8.

I can use --max_old_space_size but I tested up to 4096 and it still crashes and worse, it starts killing other processes.

dbaeumer commented 3 years ago

@ranisalt does the validation happen correctly when you use eslint in the terminal. If this is the case can you please provide me with a GitHub repository I can clone that demos what you are experiencing.

warnellw commented 3 years ago

I am experiencing the same problem in a monorepo + TypeScript environment. Setting "eslint.runtime": "node" as @kzimny suggested fixed the problem for me.

Egnus commented 3 years ago

Confirmed the same. I had this issue for months, I could not save files sometimes because eslint never finished doing is lint/format/whatever actions. The CPU many times was stuck on 100%, the extensions reports were pointing always to eslint-server and I couldn't find any reason why. My monorepo had this basic setup:

I had tried many things, like root: true, or a single eslint for all the packages, disabling auto formatting, ignoring all node_modules... But "eslint.runtime": "node" is working so good that eslint finally is telling me for the first time in this monorepo that my code is wrong instantaneously after wrongly typing it, without 1 - 5 seconds delay (or never if CPU blocked) and a unstable cpu jumping from 0 - 100% for this task for no reason. Thanks @kzimny

kzimny commented 3 years ago

In addition to @JaLe29 suggestion, folders which should not be checked by eslint should be excluded in .eslintrc.json file:

{
    "root": true,
    "parserOptions": {
        "ecmaVersion": 6
    },
    "ignorePatterns": [
        "build/**/*",
        "dist/**/*",
        "mobile/**/*",
        "node_modules/**/*",
        "node-mobile/**/*",
        "node-native/**/*",
        "obj/**/*",
        "styles/**/*",
        "themes/**/*"
    ]
}
ChiefORZ commented 3 years ago

The vscode-eslint extension completely stopped working for us!!! We are using a yarn v2 (aka. berry) monorepo with the @yarnpkg/pnpify setup.

At some point our eslint settings completely stopped working on all our machines and always gave us Getting code actions from ''ESLint'' with a Code Helper Process at 100%... it vscode even tried to get code actions from ESLint - even though our setting is set to "[html]": {"editor.defaultFormatter": "vscode.html-language-features"},...

We now tried to figure out if yarn berry was the problem and installed our project with yarn v1.22.4 - problem exactly the same. Even tried to disable all other vscode extensions - and only run eslint, to figure out if it is a problem with other extensions... same result.

We now installed version 2.1.6 of vscode-eslint, which seems to work perfectly... so the bug must be somewhere between those versions.


this is a newly created next.js app, with a minimal dependencies.

// package.json
{
  "name": "with-styled-components",
  "version": "1.0.0",
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "postinstall": "husky install",
    "prepublishOnly": "pinst --disable",
    "postpublish": "pinst --enable"
  },
  "dependencies": {
    "google-map-react": "^2.1.9",
    "husky": "^6.0.0",
    "next": "latest",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-is": "^17.0.2",
    "styled-components": "^5.2.3"
  },
  "devDependencies": {
    "@yarnpkg/pnpify": "^3.0.0-rc.3",
    "babel-eslint": "^10.1.0",
    "babel-plugin-styled-components": "^1.12.0",
    "eslint": "^7.27.0",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.23.3",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-prettier": "^3.4.0",
    "eslint-plugin-react": "^7.23.2",
    "eslint-plugin-react-hooks": "^4.2.0",
    "husky": "^6.0.0",
    "pinst": "^2.0.0",
    "prettier": "^2.3.0",
    "pretty-quick": "^3.1.0"
  },
  "license": "MIT"
}
// .eslintrc.json
{
  "extends": ["airbnb", "plugin:prettier/recommended"],
  "ignorePatterns": ["build/**/*", "dist/**/*", "mobile/**/*", "node_modules/**/*", "node-mobile/**/*", "node-native/**/*", "obj/**/*", "styles/**/*", "themes/**/*"],
  "parserOptions": {
    "ecmaVersion": 6
  },
  "root": true,
  "plugins": ["prettier"],
  "rules":{
    "prettier/prettier": 2,
    "react/jsx-filename-extension": 0
  }
}
dbaeumer commented 3 years ago

@ChiefORZ since it sounds like you are able to reproduce this could you provide me with a GitHub repository I can clone that demos that?

rdsedmundo commented 3 years ago

Also facing this, I'm working around it by closing some files that I'm not actively working at the moment and restarting the server too. I have a medium monorepo, and whenever I have 8+ files open it starts to happen. Not really sure, but it might be a regression because I used to work on a considerably larger monorepo fine. And even if it's the case, it's hard to tell if it's on eslint side or vscode-eslint.

More and more it seems that we have reached the ceiling with tooling written in JS and we should go with Rust/Go instead as ESBuild and friends are doing, to achieve better performance.

dbaeumer commented 3 years ago

The number of open files shouldn't have an huge impact on the server. The server is only validating the file you are typing in, not the others.

rdsedmundo commented 3 years ago

Interesting. It might have to do with @typescript-eslint that I'm using with type-checking rules enabled, it for sure considers more than just the single file that's open.

dbaeumer commented 3 years ago

@rdsedmundo it depends on the rules you are using. If you use rules that require type resolving then typescript-eslint will read other TS/JS files and parses them. But it will not validate them.

dbaeumer commented 2 years ago

Got fixed with https://github.com/microsoft/vscode-eslint/issues/733

Qesham commented 1 year ago

I am new to the computing world so i don't know most of the things here. However, I can't do anything when it comes to my vs codespace, it takes forever to start, and when it eventually loads, it tells me it cannot connect, that I need to reload page, just after 1 minute of use. I have failed to completely have my lectures on coding in C just because i cannot use the vs codespace at all.