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

Bug: "Launching server using runtime node failed. Error: spawn node ENOENT" #1596

Closed
thernstig opened this issue Feb 1, 2023 · 71 comments
Closed
Labels
info-needed Issue requires more information from poster

Comments

@thernstig
Copy link

Type: Bug

At times when starting VS Code the ESLint server is stopped. It happens intermittently and quite seldom. Using the command ESLint: Restart ESLint Server does not help. Here is the output from the OUTPUT panel.

[Info  - 11:21:39 AM] ESLint server is starting
[Info  - 11:21:40 AM] ESLint server stopped.
[Error - 11:21:40 AM] ESLint client: couldn't create connection to server.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 11:21:40 AM] Starting the server failed.
Launching server using runtime node failed. Error: spawn node ENOENT

### Here I executed the command 'ESLint: Restart ESLint Server' from the command palette ###

[Error - 11:23:15 AM] Restarting client failed
Error: Client is not running and can't be stopped. It's current state is: startFailed
	at w.shutdown (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.2.6/client/out/extension.js:1:107590)
	at w.stop (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.2.6/client/out/extension.js:1:107171)
	at w.stop (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.2.6/client/out/extension.js:1:266246)
	at w.restart (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.2.6/client/out/extension.js:1:266113)
	at /home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.2.6/client/out/extension.js:1:376159
	at s.h (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:94:107622)
	at s.$executeContributedCommand (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:94:108311)
	at u.N (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:104:11208)
	at u.M (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:104:10926)
	at u.H (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:104:10019)
	at u.G (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:104:9000)
	at /home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:104:7788
	at d.invoke (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at v.deliver (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:2029)
	at g.fire (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:1667)
	at h.fire (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:72:14314)
	at /home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:120:15804
	at d.invoke (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at v.deliver (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:2029)
	at g.fire (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:1667)
	at h.fire (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:72:14314)
	at c.y (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:72:17324)
	at /home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:72:15795
	at d.invoke (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at v.deliver (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:2029)
	at g.fire (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:1667)
	at g.acceptChunk (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:72:12045)
	at /home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:72:11332
	at d.invoke (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at v.deliver (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:2029)
	at g.fire (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:63:1667)
	at g.t (/home/userA/.vscode-server/bin/97dec172d3256f8ca4bfb2143f3f76b503ca0534/out/vs/workbench/api/node/extensionHostProcess.js:72:25895)

Using the terminal, node does exist:

> node --version
v18.12.1
> which node
/home/userA/.local/share/nvm/v18.12.1/bin/node

I have set "eslint.runtime": "node", both in the user and workspace settings.json files.

I have no idea what could be wrong. I have been using the ESLint extension for years, but this started to happen more recently within the past few months.

Extension version: 2.2.6
VS Code version: Code 1.74.3 (97dec172d3256f8ca4bfb2143f3f76b503ca0534, 2023-01-09T16:59:02.252Z)
OS version: Windows_NT x64 10.0.19044
Modes:
Sandboxed: No
Remote OS version: Linux x64 5.4.0-137-generic

System Info
Item Value
CPUs 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz (8 x 2611)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 31.69GB (18.23GB free)
Process Argv --crash-reporter-id e332dab4-91ea-49d1-8a1f-d8f6e06fa4e1
Screen Reader no
VM 0%
Item Value
Remote SSH: vm
OS Linux x64 5.4.0-137-generic
CPUs Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (8 x 2394)
Memory (System) 31.33GB (27.66GB free)
VM 18%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes627:30244334
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vscaat:30438848
vsclangdc:30486549
c4g48928:30535728
dsvsc012cf:30540253
azure-dev_surveyonecf:30548226
pyindex848cf:30577861
nodejswelcome1cf:30587006
2e4cg342:30602488
f6dab269:30613381

@dbaeumer
Copy link
Member

dbaeumer commented Feb 2, 2023

Very hard to say why the node runtime is not found.

Why are you using your own? VS Code ships with a node runtime that is suitable for most use cases. Can you try to remove the settings eslint.runtime and see what happens?

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Feb 2, 2023
@rdsedmundo
Copy link

This started to happen to me randomly too, had never seen it before using the extension for years. Removing eslint.runtime makes it work again with the default Node version, but I wanted it to use my specific version.

@thernstig
Copy link
Author

@dbaeumer the use case to use our own runtime is of course that all our ESLint tests run with constructs available in the Node.js version we use? Or am I missing something?

@dbaeumer
Copy link
Member

In which setting file do you make that change. If you are running for example in WSL you need to change that setting in the Remote settings image and not in the User settings.

@thernstig
Copy link
Author

We run with remote SSH, and set the setting in the workspace settings. Would it work if we set them in the remote SSH settings?

image

We have had them set in the workspace settings for a long time, does that mean it never worked? Why is the setting not greyed out like it is in the user settings then (I can see reasons for this, but asking as a sanity question)?

image

But our end goal is this: We are a team of developers that always install Node on our local machines, all using the same version (we enforce it via nvm). We want to make sure all of us use the same version of the node binary, due to that ESLint construct (functions etc.) usage depends on version of Node.js.

Is there no way then to achieve this than to ask all developers to set this themselves in the remote SHH config?

@rdsedmundo
Copy link

rdsedmundo commented Mar 13, 2023

I'm running in macOS, and changing the config via .vscode/settings.json. I use volta to manage my Node.js version if that matters, and again, this has been working for years and somehow it broke in the last <2 weeks now.

@dbaeumer
Copy link
Member

@thernstig you can also set it in the workspace settings (e.g..vscode/settings.json). When you run in a remote SSH setup the ESLint extension run on the remote machine, hence the settings of the remote machine apply and not the local user settings. This is how VS Code works.

@rdsedmundo I just tested this locally and using eslint.runtime in the workspace settings still works for me. Can you check with some sort of process explorer to see which node process is used to run the dbaeumer.vscode-eslint-2.4.0/server/out/eslintServer.js under

@thernstig
Copy link
Author

thernstig commented Mar 14, 2023

@dbaeumer of that I am aware. What I wondered was if setting it in workspace settings did not work, considering you said that for WSL I needed to set it there. But from your text above it seems you confirmed setting it in .vscode/settings.json should work also for the setting "eslint.runtime": "node".

But then if it is allowed to set it in the workspace settings when running with remote SSH, I would guess there is a newly introduced bug somewhere. I never seen this before for years, but it started to happen recently probably during the last VS Code or ESLint extension upgrade.

As we mention this is very seldom and happens only sometimes. So some kind of race condition seems at play here.

Is there anything I can do, once this happened, to gather some logs? Without restarting anything?

@rdsedmundo
Copy link

@dbaeumer this is super weird, I haven't really changed anything but from yesterday to today it started working again... I'll let you know if it breaks again and try to check for the process info as you suggested.

@dbaeumer
Copy link
Member

@thernstig you could enable tracing in the ESLint server using "eslint.trace.server": "messages". When it happens you could provide me with the ESLint output channel which should have some information about which node version got used.

@thernstig
Copy link
Author

thernstig commented Mar 15, 2023

@dbaeumer will do. Will report back with the traces if I get the fault again.

To summarize all these lengthy discussions:
We set "eslint.runtime": "node" in our workspace settings .vscode/settings.json and have been for year(s). We recently started to get the faults seen in the original post. Hence I assume it is a bug as it should not occur.

@koshic
Copy link

koshic commented Mar 24, 2023

@dbaeumer have the same issue recently. May be it related to https://github.com/lukechilds/zsh-nvm (need to investigate a bit), because "eslint.runtime": "MY_HOME/.nvm/versions/node/v19.8.1/bin/node" (from 'which node' in integrated terminal) works fine.

Stack trace with 'node':

[Info  - 01:59:29] ESLint server is starting.
[Info  - 01:59:30] ESLint server stopped.
[Error - 01:59:30] ESLint client: couldn't create connection to server.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 01:59:30] Starting the server failed.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 01:59:37] Restarting client failed
Error: Client is not running and can't be stopped. It's current state is: startFailed
	at w.shutdown (<my home>/.vscode/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:103973)
	at w.stop (<my home>/.vscode/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:103554)
	at w.stop (<my home>/.vscode/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:265270)
	at w.restart (<my home>/.vscode/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:265137)
	at <my home>/.vscode/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:382698
	at c.h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:96:108784)
	at c.$executeContributedCommand (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:96:109688)
	at a.N (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:106:11223)
	at a.M (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:106:10941)
	at a.H (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:106:10034)
	at a.G (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:106:9015)
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:106:7803
	at f.invoke (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at m.deliver (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:63:2066)
	at d.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:63:1704)
	at p.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:72:14907)
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:122:16556
	at f.invoke (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at m.deliver (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:63:2066)
	at d.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:63:1704)
	at p.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:72:14907)
	at MessagePortMain.<anonymous> (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:122:14682)
	at MessagePortMain.emit (node:events:526:28)
	at MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:5:364)

@dbaeumer
Copy link
Member

The ESLint server is relying on the fact that node is available on the PATH or you provided an absolute path to it. If zsh-nvm does some PATH magic it certainly might be the cause of this issue.

@koshic
Copy link

koshic commented Mar 27, 2023

Sure, I just provided my temporary issue as an illustration, because it was fixed by proper nvm setup.

BTW, may be it's possible to improve error message a bit? "Error: spawn node ENOENT" -> 'Error: spawn node ENOENT, PATH=xxx, cwd=yyy', or something like that. Now it's a black box, and debugging (especially for people not so familiar with OS / shell) is really hard.

@rdsedmundo
Copy link

@dbaeumer I was able to reproduce this consistently now, for my case it happens when I log out of my computer and check the option Reopen windows when logging back in, and then log in again. Even if I perform "VSCode: Reload window" several times it still doesn't work, however if I fully kill the process (CMD+Q) and re-open it, then the config works again.

This used to work in the past as I had mentioned above, because I have been using this extension for years. I'd imagine though this is more likely to be either a regression in VSCode itself, or in the newer versions of MacOS that changed something? I have macOS 13.2.1.

@thernstig
Copy link
Author

This failure is done for me in VS Code in Windows, working remotely against an SSH machine. So it is not macOS specific.

As mentioned before, this has never been a problem before but starting occurring a few releases ago.

@dbaeumer
Copy link
Member

dbaeumer commented Apr 4, 2023

I tried to reproduce this in a local SSH setup but wasn't able to do so. I actually thing that this is not caused by the ESLint extension itself but may be some change in the remote SSH extension and how it sets up the environment. @thernstig what happens if you use an absolute path to the node executable. Does it happen as well?

@thernstig
Copy link
Author

@dbaeumer I have not tested, but that is not feasible for me as we use nvm and automatically load the version per project. Which we have done for years and not had this problem I see here now. Of course it could be one of the culprits for the reason this happens.

@dbaeumer if you want to keep the issue list clean, I am fine with closing this until I can actually prove exactly what happens. I have added "eslint.trace.server": "messages" as you recommended earlier, so if it happens again I might understand it better looking at the logs from ESlint.

@dbaeumer
Copy link
Member

Thanks for investigating further.

I will still keep the issue open

@thernstig
Copy link
Author

thernstig commented Apr 12, 2023

@dbaeumer I just got the issue again. I have set "eslint.trace.server": "messages" both in the User, Remote SSH and Workspace settings. It seems to give no information about which Node version gets used. Probably because the error indicates it does not even find it.

Restarting VS Code does not help.

[Info  - 5:29:08 PM] ESLint server is starting.
[Info  - 5:29:08 PM] ESLint server stopped.
[Error - 5:29:08 PM] ESLint client: couldn't create connection to server.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 5:29:08 PM] Starting the server failed.
Launching server using runtime node failed. Error: spawn node ENOENT

If I open the terminal I see:

~/code/projectA (jsdoc)> node -v
v18.14.2

Using the command ESLint: Restart ESLint Server does not help.

[Info  - 5:30:58 PM] ESLint server is starting.
[Info  - 5:30:58 PM] ESLint server stopped.
[Error - 5:30:58 PM] ESLint client: couldn't create connection to server.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 5:30:58 PM] Starting the server failed.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 5:32:36 PM] Restarting client failed
Error: Client is not running and can't be stopped. It's current state is: startFailed
	at w.shutdown (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:103911)
	at w.stop (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:103492)
	at w.stop (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:265208)
	at w.restart (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:265075)
	at /home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.0/client/out/extension.js:1:382636
	at m.h (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:99:125797)
	at m.$executeContributedCommand (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:99:126701)
	at c.N (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:109:11655)
	at c.M (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:109:11373)
	at c.H (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:109:10454)
	at c.G (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:109:9432)
	at /home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:109:8220
	at E.invoke (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at h.deliver (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:2121)
	at n.fire (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:1729)
	at p.fire (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:72:14916)
	at /home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:125:16654
	at E.invoke (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at h.deliver (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:2121)
	at n.fire (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:1729)
	at p.fire (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:72:14916)
	at s.E (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:72:18982)
	at /home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:72:16970
	at E.invoke (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at h.deliver (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:2121)
	at n.fire (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:1729)
	at d.acceptChunk (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:72:12647)
	at /home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:72:11934
	at E.invoke (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:145)
	at h.deliver (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:2121)
	at n.fire (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:63:1729)
	at n.u (/home/userA/.vscode-server/bin/e344f1f539a80912a0e9357cec841f36ce97a4e2/out/vs/workbench/api/node/extensionHostProcess.js:72:28899)

Disabling the ESLint plugin, reloading VS Code, and enabling it again (without reloading) does make it work again.

@dbaeumer
Copy link
Member

I looked through the code again and what happens is the following:

  • the client tries to spawn the server using child_process.spawn('node', ....)
  • node for some reason isn't on the path hence it can't be found and the client can't start the server.

@roblourens do you have any idea why node can't be found sometimes in a remote ssh setup

@thernstig is it important for you to use a custom runtime. If you are happy with node 16.17.1 you can remove the setting and simply use the node version VS Code bundles.

@thernstig
Copy link
Author

thernstig commented Apr 13, 2023

@dbaeumer it is important, as some ESLint features depend on what ECMAScript version is used, which correlates with the Node.js version.

Here is an idea why node is not on the path at times. It seems me and others use systems to load the node version per project/directory. E.g. via direnv or other similar means.

Basically what happens is that the node binary is on the path once the shell has completed loading. In this case the fish shell. See here:

~/code/projectA (TEST)> which node
/home/userA/.local/share/nvm/v18.14.2/bin/node
~/code/projectA (TEST)> cd ..
direnv: unloading
~/code> which node
~/code [1]> cd projectA/
direnv: loading ~/code/projectA/.envrc
direnv: using nvm
direnv: using node
direnv: Successfully loaded NodeJS v18.14.2 (via .nvmrc), from prefix (/home/userA/.local/share/nvm/v18.14.2)
direnv: export +ANSIBLE_CONFIG +CPATH +DOCKER_BUILDKIT +KUBECONFIG +LD_LIBRARY_PATH +LIBRARY_PATH +MANPATH +PKG_CONFIG_PATH +PLAYWRIGHT_BROWSERS_PATH ~PATH
~/code/projectA (TEST)> which node
/home/userA/.local/share/nvm/v18.14.2/bin/node
~/code/projectA (TEST)>

Is it that child_process.spawn('node', ....) is spawned before the shell has loaded?

@roblourens
Copy link
Member

@roblourens do you have any idea why node can't be found sometimes in a remote ssh setup

Which "node" is this supposed to be? Do we add it to PATH?

@dbaeumer
Copy link
Member

Actually that would be something @roblourens needs to answer. The extension host sees the environment of the remote server which I don't know in which shell context it is started.

@roblourens
Copy link
Member

Sorry I don't fully understand the situation, but in other places I'm aware of when an extension wants to spawn its own node process, I think that we spawn process.execPath which is the EH's node. If you spawn node then you might get the user's node or something else.

@koshic
Copy link

koshic commented Apr 14, 2023

I think it's need to add some debug code into extension itself and dump PATH / env / 'which node' right before spawn call.

@dbaeumer
Copy link
Member

@roblourens The eslint code calls child_process.spawn('node', ....) which in a normal setup executes a locally installed node not the one that comes with Electron. For some reason that node executable isn't found (interestingly not always).

@dbaeumer
Copy link
Member

@koshic good idea. I will log the PATH when starting the server fails.

@roblourens
Copy link
Member

Now I understand, thanks. If you grab the log from the Remote-SSH output channel, you can see the environment the the vscode server was started in. That's the environment that the remote server gets and that is inherited by the remote EH.

You called out the fish shell- actually we usually fail to connect at all when fish is the default shell for ssh connections microsoft/vscode-remote-release#2509. But it seems likely that some configuration script you have isn't getting run in this case so node is left out of your PATH.

@dbaeumer
Copy link
Member

dbaeumer commented Dec 4, 2023

I will close the issue. For the request of using a default installed Node version see #1727.

@dbaeumer dbaeumer closed this as completed Dec 4, 2023
@thernstig
Copy link
Author

@dbaeumer I have not seen this issue in a long time now, but I will surely revert back if it happens again. Thanks for your patience and kind support.

@thernstig
Copy link
Author

@dbaeumer I ran into this again:

[Info  - 1:49:05 PM] ESLint server is starting.
[Info  - 1:49:05 PM] ESLint server stopped.
[Error - 1:49:05 PM] ESLint client: couldn't create connection to server.
Launching server using runtime node failed. Error: spawn node ENOENT
[Error - 1:49:05 PM] Starting the server failed.
Launching server using runtime node failed. Error: spawn node ENOENT
[Info  - 1:49:05 PM] PATH environment variable is: /home/userA/.vscode-server/bin/903b1e9d8990623e3d7da1df3d33db3e42d80eda/bin/remote-cli:/home/userA/.pyenv/shims:/home/userA/.pyenv/bin:/home/userA/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

I am fairly certain I know the cause of this.

We are using https://github.com/direnv/direnv-vscode. Basically it loads the environment and augmenst the PATH variable with e.g. the path to the node binary. This is how it looks when I open the VS Code terminal (or any terminal) where the enrivonment is complete. See the nvm part.

Is this a race condition where something loads things into the environment, and this extension does not pick it up because it starts "too early". Can/should this extension look for environment changes and reload or restart the ESLint server when found?

$PATH[1]: |/home/userA/code/projectA/bob|
$PATH[2]: |/home/userA/code/projectA/.venv/bin|
$PATH[3]: |/home/userA/code/projectA/node_modules/.bin|
$PATH[4]: |/home/userA/.local/share/nvm/v20.10.0/bin|
$PATH[5]: |/home/userA/code/projectA/devenv_temp/bin|
$PATH[6]: |/home/userA/code/projectA/scripts/dev|
$PATH[7]: |/home/userA/code/projectA/tests/brand1_e2e|
$PATH[8]: |/home/userA/.pyenv/shims|
$PATH[9]: |/home/userA/.pyenv/bin|
$PATH[10]: |/home/userA/.local/bin|
$PATH[11]: |/usr/local/sbin|
$PATH[12]: |/usr/local/bin|
$PATH[13]: |/usr/sbin|
$PATH[14]: |/usr/bin|
$PATH[15]: |/sbin|
$PATH[16]: |/bin|
$PATH[17]: |/usr/games|
$PATH[18]: |/usr/local/games|
$PATH[19]: |/snap/bin|
$PATH: originally inherited as |/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin|

@dbaeumer
Copy link
Member

There are no events for environment changes so there is nothing I can listen for. I do see the problem however I can't think about a proper solution except of restarting the server manually when you see the issue. The eslint extension activates on onStartupFinished which is basically very late in the activation phases.

A hack that could be investigated is to check if the direnv extension is installed and wait for their activation to be finished before starting the server.

@dbaeumer
Copy link
Member

Would you be interested in looking into a PR for such a hack?

@thernstig
Copy link
Author

@dbaeumer possibly, though I personally feel wary about such a solution where an extension (vscode-eslint) depends/checks for one other specific extension (direnv-vscode), as there could be other extensions altering the environment. Maybe it is an intermediate solution and a post should be made on https://github.com/microsoft/vscode/? I am not sure how to phrase such an issue there though, or if it would even get attention.

What I have seen is that restarting the ESLint server does not help either. What would that indicate?

@dbaeumer
Copy link
Member

What I have seen is that restarting the ESLint server does not help either. What would that indicate?

The ESLint server inherits the environment from the extension host (e.g. the process running all extensions). If a restart doesn't help that means that the extension host doesn't have an updated environment either. I actually don't know how the direnv extension is altering the envirnment to understand why it is not reflected in the extension host.

@thernstig
Copy link
Author

thernstig commented Feb 26, 2024

@dbaeumer I think I have some investigation to do then. To understand if direnvv-vscode should change its code, or if the extension host from VS Code needs an update or a new event to handle someone trying to update the environment (could be a security issue of course). Hmm. All open for advice.

@dbaeumer
Copy link
Member

One idea to find this out is using a dummy extension and run it under the debugger and inspect process.env.

@thernstig
Copy link
Author

thernstig commented Feb 28, 2024

@dbaeumer thanks for the idea, a bit over my knowledge level as I never authorened an , but I will let this simmer a bit more. I suppose the idea of posting this as a feature request at the vscode repo, for a new event, is not a good idea then?

@dbaeumer
Copy link
Member

dbaeumer commented Mar 1, 2024

@thernstig I think we need to first understand what exactly direnvv-vscode does to inject the environment.

@mkhl
Copy link

mkhl commented Mar 7, 2024

hi there,

I think we need to first understand what exactly direnvv-vscode does to inject the environment.

we inject the environment by modifying process.env, see https://github.com/direnv/direnv-vscode/blob/main/src/extension.ts#L223-L230.
we also define an environmentVariableCollection that's used for tasks and terminals but that shouldn't matter to this issue.

@thernstig we also log which changes we apply to the environment, in the Output panel look for direnv in the dropdown

as for startup order, we try to activate direnv as early as possible (* and onLanguage) but sometimes it's still too late, see direnv/direnv-vscode#109
at least for the ocaml lsp this was fixed by reading the environment on use instead of on activation (ocamllabs/vscode-ocaml-platform#1322)

@thernstig
Copy link
Author

thernstig commented Mar 11, 2024

@dbaeumer with the info from @mkhl above, I can only see two options:

  1. VS Code implements a new event, interface etc. to handle extensions wanting to update environments, and that extensions can listen for environment updates.
  2. That vscode-eslint does a similar solution as recompute env dict on every command ocamllabs/vscode-ocaml-platform#1322

Any more ideas?

@dbaeumer
Copy link
Member

I actually do (2). When I launch the server I has Node API to do so which takes the current env into consideration.

The other workaround I see is to add a setting that makes this extension wait for the activation of the env extension.

@thernstig
Copy link
Author

Well, then I am stumped. @dbaeumer I do not understand how the extension can take the latest env on commands, since the original problem described even happens when executing the command ESLint: Restart ESLint Server, which I then would assume would take the latest env and then it should have worked.

@dbaeumer
Copy link
Member

I don't understand it either. Every time the server starts I freshly read the environment from the process environment here: https://github.com/microsoft/vscode-languageserver-node/blob/691fd5d3fabeed5ed8ff9c3608f2d306cb07717e/client/src/node/main.ts#L248

What you could do is may be to patch that method in JS and console.error the environment to see if the environment looks like expected when restarting the server.

@thernstig
Copy link
Author

@dbaeumer is that code doing what 2) above shows as in ocamllabs/vscode-ocaml-platform#1322? It says it does it on every command, not every server start. It is possible I misunderstood you of course.

@mkhl are you comfortable enough reading this extensions code to see something? I am unfortunately not wellversed in VS Code extension authoring.

@dbaeumer
Copy link
Member

@thernstig the eslint server is a separate process with its own environment. What I ensure is that I inject the CURRENT extension host environment into that process when I launch the server. So if direnv has changed the env and the server is re-started it should see that env.

@thernstig
Copy link
Author

@dbaeumer then it is possible the problem for restarting is another one, as it does not want to do that:

[Error - 9:33:46 AM] Restarting client failed
Error: Client is not running and can't be stopped. It's current state is: startFailed
	at b.shutdown (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.4/client/out/extension.js:1:104688)
	at b.stop (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.4/client/out/extension.js:1:104269)
	at b.stop (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.4/client/out/extension.js:1:270385)
	at b.restart (/home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.4/client/out/extension.js:1:270252)
	at /home/userA/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.4/client/out/extension.js:1:387592
	at u.h (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:150:184839)
	at u.$executeContributedCommand (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:150:185699)
	at s.S (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:147:5519)
	at s.Q (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:147:5285)
	at s.M (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:147:4375)
	at s.L (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:147:3454)
	at p.value (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:147:2241)
	at n.y (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:80:1902)
	at n.fire (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:80:2119)
	at r.fire (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:105:14091)
	at p.value (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:173:8050)
	at n.y (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:80:1902)
	at n.fire (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:80:2119)
	at r.fire (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:105:14091)
	at u.z (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:105:17156)
	at p.value (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:105:15608)
	at n.y (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:80:1902)
	at n.fire (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:80:2119)
	at p.acceptChunk (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:105:11865)
	at /home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:105:11152
	at Socket.y (/home/userA/.vscode-server/cli/servers/Stable-863d2581ecda6849923a2118d93a088b0745d9d6/server/out/vs/workbench/api/node/extensionHostProcess.js:170:13198)
	at Socket.emit (node:events:514:28)
	at addChunk (node:internal/streams/readable:324:12)
	at readableAddChunk (node:internal/streams/readable:297:9)
	at Readable.push (node:internal/streams/readable:234:10)
	at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

@dbaeumer
Copy link
Member

Is there anything more in the Output channel. Looks like a previous restart has failed.

@thernstig
Copy link
Author

thernstig commented Mar 14, 2024

@dbaeumer it is the same output as in the original post, which contains the entire output. The previous start failed due to node not being found. Then restarting the client does not fail. It should have if it re-reads the env as the extension host env should contain the proper PATH.

@mkhl
Copy link

mkhl commented Mar 14, 2024

@thernstig have you checked the direnv Output channel? Does it set the PATH you're expecting?

If I understand correctly you're observing the problem in remote SSH workspaces. Does it also occur in local workspaces?

@thernstig
Copy link
Author

@mkhl I have not received the problem again and have not been able to check. I will report back once I see it. It is very intermittent.

It only occurs on remote SSH workspaces. I never use local workspaces, and since it is intermittent it is hard to reproduce.

@dbaeumer
Copy link
Member

The previous start failed due to node not being found. Then restarting the client does not fail. It should have if it re-reads the env as the extension host env should contain the proper PATH.

This explains why the restart doesn't work. The restart fails because the original start fails since it is using the same client object to not loose any internal client state when restarting the server.

What we could do is to use a new client in the restart case if a previous start failed.

I opened #1808

@thernstig
Copy link
Author

@dbaeumer that will most likely at least solve the restart part yay :)

Is there a chance that if a start fails, you do a setTimeout() for 1 sec to try to create a new client (thus making sure you get a new fresh environment fron the extension host)? Maybe not a great solution in the end, but just asking.

I am still curious if you think I should open a VS Code issue to ask for an extension API regarding environment changes? You are far better of to judge if that would make sense or not than I am.

@dbaeumer
Copy link
Member

I am still curious if you think I should open a VS Code issue to ask for an extension API regarding environment changes? You are far better of to judge if that would make sense or not than I am.

Honestly I think such an API request will not be implemented due to the fact the NodeJS doesn't provide it. It would a require poll/compare implementation which is never good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

9 participants