vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

ECONNREFUSED with `networkingMode=VirtioProxy` and `localhostForwarding=true`

Open KamilFil opened this issue 7 months ago • 36 comments

Type: Bug

Failed to connect to the remote extension host server (Error: WebSocket close with status code 1006)

Show Log

NodeExecServer run: C:\Windows\System32\wsl.exe -d Ubuntu-22.04 -e /home/xxx/.vscode-server/bin/xxx/node -e const net = require('net'); process.stdin.pause(); const client = net.createConnection({ host: '127.0.0.1', port: 36789 }, () => { client.pipe(process.stdout); process.stdin.pipe(client); }); client.on('close', function (hadError) { console.error(hadError ? 'Remote close with error' : 'Remote close'); process.exit(hadError ? 1 : 0); }); client.on('error', function (err) { process.stderr.write(err && (err.stack || err.message) || String(err)); })

What I've tried so far

  • Fully restarted VSCode after each change.

  • Checked .wslconfig on Windows and confirmed:

[network] generateResolvConf = false

  • Edited /etc/resolv.conf inside WSL to:

nameserver 1.1.1.1

  • Temporarily disabled my firewall (Avast) – no change.
  • I also tried resolving the problem using the solution(s) described in this related issue:

https://github.com/microsoft/vscode/issues/130887

Extension version: 0.99.0 VS Code version: Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e, 2025-05-14T21:47:40.416Z) OS version: Windows_NT x64 10.0.22631 Modes:

System Info
Item Value
CPUs 12th Gen Intel(R) Core(TM) i7-12700H (20 x 2688)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
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_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) undefined
Memory (System) 15.71GB (5.35GB free)
Process Argv --crash-reporter-id 0cf7310d-efd0-4516-a674-2452eddf47a1
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
pythonrstrctxt:31112756
nativeloc2:31192216
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
e5gg6876:31282496
pythoneinst12:31285622
bgtreat:31268568
4gafe986:31271826
c7cif404:31314491
6gi0g917:31259952
996jf627:31283433
pythonrdcb7cf:31303019
usemplatestapi:31297334
0aa6g176:31307128
7bj51361:31289155
747dc170:31275177
9hi5e907:31309499
pylancecolor:31314202
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
gendocf:31295004
9d2cg352:31309727

KamilFil avatar May 28 '25 19:05 KamilFil

Not sure if it's related, but I've been having intermittent issues with WSL + VSCode (devcontainer) over the last 24 hours.

Occasionally, when trying to connect to WSL, VSCode will hang for about two minutes before failing.

The only way I've found to temporarily resolve the issue is to forcefully stop the WSL service. wsl --shutdown doesn't work, I need to run taskkill /F /im wslservice.exe.

It's more likely that WSL is the cause and not VSCode, but I'm posting anyways in case it brings more insight.

Logs:

[11 ms] Dev Containers 0.413.0 in VS Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e).
[10 ms] Start: Run: wsl -d Ubuntu -e wslpath -u \\wsl.localhost\Ubuntu\...
[60099 ms] Start: Resolving Remote
[60188 ms] Start: Run: wsl -d Ubuntu -e wslpath -u \\wsl.localhost\Ubuntu\...
# Hangs for ~2 minutes before timing out

eliasbenb avatar May 28 '25 20:05 eliasbenb

Not sure if it's related, but I've been having intermittent issues with WSL + VSCode (devcontainer) over the last 24 hours.

Occasionally, when trying to connect to WSL, VSCode will hang for about two minutes before failing.

The only way I've found to temporarily resolve the issue is to forcefully stop the WSL service. wsl --shutdown doesn't work, I need to run taskkill /F /im wslservice.exe.

It's more likely that WSL is the cause and not VSCode, but I'm posting anyways in case it brings more insight.

Logs:

[11 ms] Dev Containers 0.413.0 in VS Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e).
[10 ms] Start: Run: wsl -d Ubuntu -e wslpath -u \\wsl.localhost\Ubuntu\...
[60099 ms] Start: Resolving Remote
[60188 ms] Start: Run: wsl -d Ubuntu -e wslpath -u \\wsl.localhost\Ubuntu\...
# Hangs for ~2 minutes before timing out

I'm having the same issue for the last few days, I'm guessing this issue started at the same time for everyone, possibly due to a windows update.

I have tried every possible fix available in the internet and not on the internet, nothing worked. Clean reinstalled vscode and wsl distro also.

  • WSL1 works fine, this is a WSL2 issue.

TahmeedBD avatar May 31 '25 04:05 TahmeedBD

If you're still having issues, try closing all your vs code windows then run :

wsl
#Then in wsl
rm -rf ~/.vscode-server

Worked for me.

Yodwaae avatar Jun 02 '25 08:06 Yodwaae

Same Issue. I follow the instruction from this. It didn't work.

CJCHEN1230 avatar Jun 02 '25 11:06 CJCHEN1230

Same issue here — everything worked fine a few weeks ago, but now VS Code fails to connect to WSL. WSL: code-server fails to start — ECONNREFUSED, dynamic port forwarding broken

I've tried:

  • Full reinstall of VS Code and Remote - WSL extension (including older versions)
  • Clearing .vscode-server, WSL cache, and logs
  • Restarting WSL, Docker, and Windows multiple times

Still getting:

Error: connect ECONNREFUSED 127.0.0.1:<random-port>

If I manually run code-server on a fixed port (e.g. 43225) inside WSL, it works and responds correctly to curl, so the WSL network stack is fine. But VS Code can't connect when it tries to start it dynamically with --port=0.

This appears to be a regression in how VS Code bridges dynamic ports between Windows and WSL.

Would appreciate clarification or workaround.

hooy avatar Jun 02 '25 20:06 hooy

My workaround for VS Code WSL ECONNREFUSED Issue

If VS Code fails with repeated ECONNREFUSED errors on a dynamic port (e.g., 127.0.0.1:40237):

  1. Find the failed port in the logs (look for: connect ECONNREFUSED 127.0.0.1:<PORT>).

  2. Manually start the server in WSL using that port:

bash
 ~/.vscode-server/bin/<hash>/node \
   ~/.vscode-server/bin/<hash>/out/server-main.js \
   --host=127.0.0.1 \
   --port=<PORT_FROM_LOGS> \
   --connection-token=random \
   --use-host-proxy \
   --disable-websocket-compression \
   --accept-server-license-terms
  1. Tell VS Code to use that port:
mkdir -p ~/.vscode-server/server-env-setup
echo "VSCODE_SERVER_REMOTE_PORT=<PORT_FROM_LOGS>" > ~/.vscode-server/server-env-setup/env
  1. restart VS code on Windows machine

Another solution that worked for me was to fully reinstall WSL:

  • backup everything wsl --export Ubuntu-22.04 ubuntu-backup.tar
  • wsl --unregister Ubuntu-22.04
  • wsl --import Ubuntu-22.04 C:\WSL\Ubuntu-22.04 ubuntu-backup.tar

It will reset everything but your files will be restored, after this for me there was few network issues which I resolved by

  • set networkingMode=mirrored
  • Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
  • Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Then just reenabled them and everything worked fine. NB! You need to reinstall your libs/packages etc inside WSL

  • Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
  • Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

hooy avatar Jun 02 '25 20:06 hooy

Solved the issue after resetting windows. Nothing else seemed to work. Did it after almost 3 years.

TahmeedBD avatar Jun 13 '25 09:06 TahmeedBD

My workaround for VS Code WSL ECONNREFUSED Issue

If VS Code fails with repeated ECONNREFUSED errors on a dynamic port (e.g., 127.0.0.1:40237):

  1. Find the failed port in the logs (look for: connect ECONNREFUSED 127.0.0.1:<PORT>).
  2. Manually start the server in WSL using that port:
bash
 ~/.vscode-server/bin/<hash>/node \
   ~/.vscode-server/bin/<hash>/out/server-main.js \
   --host=127.0.0.1 \
   --port=<PORT_FROM_LOGS> \
   --connection-token=random \
   --use-host-proxy \
   --disable-websocket-compression \
   --accept-server-license-terms
  1. Tell VS Code to use that port:
mkdir -p ~/.vscode-server/server-env-setup
echo "VSCODE_SERVER_REMOTE_PORT=<PORT_FROM_LOGS>" > ~/.vscode-server/server-env-setup/env
  1. restart VS code on Windows machine

Another solution that worked for me was to fully reinstall WSL:

  • backup everything wsl --export Ubuntu-22.04 ubuntu-backup.tar
  • wsl --unregister Ubuntu-22.04
  • wsl --import Ubuntu-22.04 C:\WSL\Ubuntu-22.04 ubuntu-backup.tar

It will reset everything but your files will be restored, after this for me there was few network issues which I resolved by

  • set networkingMode=mirrored
  • Disable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform
  • Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Then just reenabled them and everything worked fine. NB! You need to reinstall your libs/packages etc inside WSL

  • Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
  • Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Same issue when setting the wsl network mode to VirtioProxy. Under this mode, when starting the code-server using --port=0 the picked port cannot be connected even inside the wsl. However if the code-server is started using the same port picked previously, the port can be connected.

The issue is gone if switched to other network mode.

EDIT: the networkingMode=VirtioProxy and localhostForwarding=true combination will cause this issue. that is when binding a 0 port. the returned port is not accessible.

python3 -m http.server -b 127.0.0.1 0
Serving HTTP on 127.0.0.1 port 39011 (http://127.0.0.1:39011/) ...

telnet 127.0.0.1 39011 
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

Serendo avatar Jul 16 '25 10:07 Serendo

My workaround is to change the r.push("--port=0") into r.push("--port=30000") or any port you want to use in the file .vscode/extensions/ms-vscode-remote.remote-wsl-0.99.0/dist/node/wslDaemon.js and stop the plugin from auto update. This works with networkingMode=VirtioProxy and localhostForwarding=true in wsl.

Serendo avatar Jul 16 '25 12:07 Serendo

I am also facing this issue and not working for me

kalyanteja19 avatar Jul 17 '25 09:07 kalyanteja19

My workaround is to change the r.push("--port=0") into r.push("--port=30000") or any port you want to use in the file .vscode/extensions/ms-vscode-remote.remote-wsl-0.99.0/dist/node/wslDaemon.js and stop the plugin from auto update. This works with networkingMode=VirtioProxy and localhostForwarding=true in wsl.

Can you suggest how to update r.push configurations?

kalyanteja19 avatar Jul 17 '25 09:07 kalyanteja19

My workaround is to change the r.push("--port=0") into r.push("--port=30000") or any port you want to use in the file .vscode/extensions/ms-vscode-remote.remote-wsl-0.99.0/dist/node/wslDaemon.js and stop the plugin from auto update. This works with networkingMode=VirtioProxy and localhostForwarding=true in wsl.

Can you suggest how to update r.push configurations?

just open the file using notepad and search for "--port=0" and change it.😁

you can goto the plugin's location by clicking the size link on the installed plugin's info page.

Serendo avatar Jul 17 '25 11:07 Serendo

Started having the same issues recently.

"Failed to connect to the remote extension host server (Error: WebSocket close with status code 1006)"

Not sure what has changed. I've been working on the same repo and setup for awhile. No changes or additional extensions that should have changed anything between it working and not working. Possibly an update of windows or vscode at some point?

I've tried the following without any luck:

  1. Restarting Windows
  2. Restarting WSL: wsl --shutdown & wsl (from CMD)
  3. Removing the vscode server from WSL: rm -rf ~/.vscode-server (from WSL)
  4. Trying to initiate the connection from WSL: code . (from WSL)
  5. Trying the initiate the connection from vscode: >WSL: Connect to WSL (from vscode)

I did notice the following WSL message upon restarting windows and WSL:

wsl: Failed to configure network (networkingMode Nat), falling back to networkingMode VirtioProxy.

JasonQueen94 avatar Jul 28 '25 03:07 JasonQueen94

Started having the same issues recently.

"Failed to connect to the remote extension host server (Error: WebSocket close with status code 1006)"

Not sure what has changed. I've been working on the same repo and setup for awhile. No changes or additional extensions that should have changed anything between it working and not working. Possibly an update of windows or vscode at some point?

I've tried the following without any luck:

  1. Restarting Windows
  2. Restarting WSL: wsl --shutdown & wsl (from CMD)
  3. Removing the vscode server from WSL: rm -rf ~/.vscode-server (from WSL)
  4. Trying to initiate the connection from WSL: code . (from WSL)
  5. Trying the initiate the connection from vscode: >WSL: Connect to WSL (from vscode)

I did notice the following WSL message upon restarting windows and WSL:

wsl: Failed to configure network (networkingMode Nat), falling back to networkingMode VirtioProxy.

Have you tried the mirrored network mode or disabling localhostForwarding?

Serendo avatar Jul 29 '25 01:07 Serendo

@JasonQueen94 could you file an issue at the Microsoft/WSL GitHub repo with logs when you start up WSL and get that networking failure message?? (Instructions are in the file a new issue page). It would help us determine what's going on!

craigloewen-msft avatar Aug 06 '25 16:08 craigloewen-msft

To find out what network mode is used by your distro, run wslinfo --networking-mode in the WSL terminal.

aeschli avatar Aug 07 '25 14:08 aeschli

@microsoft/wsl-team Interesting finding: https://github.com/microsoft/vscode/issues/255211#issuecomment-3165805999

aeschli avatar Aug 08 '25 08:08 aeschli

I had the same problem with WSL 2.5.1 and superior, so I'm staying with the 2.4.x : https://github.com/microsoft/WSL/issues/12732

klecouvey avatar Aug 13 '25 21:08 klecouvey

My workaround is to change the r.push("--port=0") into r.push("--port=30000") or any port you want to use in the file .vscode/extensions/ms-vscode-remote.remote-wsl-0.99.0/dist/node/wslDaemon.js and stop the plugin from auto update. This works with networkingMode=VirtioProxy and localhostForwarding=true in wsl.

Can you suggest how to update r.push configurations?

just open the file using notepad and search for "--port=0" and change it.😁

you can goto the plugin's location by clicking the size link on the installed plugin's info page.

Confirmed, changing r.push(--port=${e.serverPort}) to r.push(--port=30000) works as a workaround. The file to change is located in : C:\Users<user> \ .vscode-insiders\extensions\ms-vscode-remote.remote-wsl-0.104.1\dist\node\wslDaemon.js

Replace with your current username.

By the way ${e.serverPort} is not defined anywhere

Kernel version: 6.6.87.2-1 WSLg version: 1.0.66 MSRDC version: 1.2.6074 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.26100.1-240331-1435.ge-release Windows version: 10.0.26100.4946

Networkmode: VirtioProxy

Tested with Vscode insider edition, but confirmed working with the standard release.

vpease avatar Aug 15 '25 15:08 vpease

I chatted with the WSL team and it's something they need to fix. They mentioned that VirtioProxy still has some issues and should be avoided So if ideally you can find a way to force a different network mode: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#main-wsl-settings has the information about that. I tried to reproduce the issue, but unfortunately I wasn't able to. I added more log output. The WSL log now shows you in which network mode you are. I also added a setting that you can choose a port where the server is running: remote.WSL.experimental.serverPort. Please try it out and let me know if that helps avoiding patching. Note that it's only a workaround.

aeschli avatar Aug 15 '25 17:08 aeschli

Unfortunately, our company uses Netskope. They recommended to use virtioproxy as it resolves their limitations.

Does the r.push work for multiple repos open?

jyee-ctm avatar Aug 18 '25 05:08 jyee-ctm

Unfortunately, our company uses Netskope. They recommended to use virtioproxy as it resolves their limitations.

Does the r.push work for multiple repos open?

yes, it does

vpease avatar Aug 18 '25 05:08 vpease

For some reason he r.push workaround doesn't always work. Sometimes it has issues reconnecting to WSL. Manually starting wsl-server works better but it is just a painful step to do.

jyee-ctm avatar Aug 22 '25 04:08 jyee-ctm

@aeschli any ETA when this will be looked at by the vscode team?

sorry unsure if you work with them or just know them.

jyee-ctm avatar Aug 22 '25 04:08 jyee-ctm

It's a WSL issue so we are waiting for the WSL team to come up with a fix for the VirtioIO mode. I don't know the ETA.

@jyee-ctm Instead of patching the r.push, did use try the remote.WSL.experimental.serverPort setting?

aeschli avatar Aug 22 '25 15:08 aeschli

@aeschli I don't see the option for remote.WSL.experimental.serverPort on the settings.json autocomplete. Is that expected?

Any idea if they have an issue open on https://github.com/microsoft/WSL?

jyee-ctm avatar Aug 24 '25 22:08 jyee-ctm

I don't see the option for remote.WSL.experimental.serverPort on the settings.json autocomplete. Is that expected? Yes, it's currently hidden

https://github.com/microsoft/WSL/issues/13256

aeschli avatar Aug 25 '25 07:08 aeschli

  • On a corp network with Zscaler and VPN . setting VirtioProxy and localhostForwarding=true is the only way for me to use WSL with a working network and access apps running inside WSL on my windows host .

Image

Workaround which works for me :

  1. Set the below in .wslconfig in windows
[wsl2]
networkingMode=VirtioProxy
localhostForwarding=false
  1. wsl --shutdown
  2. Connect to WSL from VSCode (It connected without any issues )
  3. Click on the WSL:Ubuntu icon on the bottom left and click on Close Remote Connection . Important : Do not close VSCode ; Only click on - Close Remote Connection
  4. Open the WSL Settings GUI app in the Networking tab turn on "localhost forwarding" and close the app .
  5. In VSCode that is already open connect to the WSL again (connected without any issues )
  6. In VSCode integrated terminal python3 -m http.server 8000 you will see the automatic port forwarding works in the ports tab .
  7. But the port is not accessible from windows host , if someone can figure out how to access the port this can be a workaround until an actual fix is in place .

madhankumar388 avatar Aug 30 '25 19:08 madhankumar388

It's a WSL issue so we are waiting for the WSL team to come up with a fix for the VirtioIO mode. I don't know the ETA.

@Jonathan Yee Instead of patching the r.push, did use try the remote.WSL.experimental.serverPort setting?

@aeschli In my case configuring a port via the hidden setting remote.WSL.experimental.serverPort did work. I'm able to start a remote WSL2 VSCode session without the need to patch any files.

My .wslconfig:

[wsl2]
networkingMode=VirtioProxy
localhostForwarding=false

Extension version: 0.104.2

amoosbr avatar Sep 30 '25 08:09 amoosbr

Confirmed, changing r.push(--port=${e.serverPort}) to r.push(--port=30000) works as a workaround. The file to change is located in : C:\Users \ .vscode-insiders\extensions\ms-vscode-remote.remote-wsl-0.104.1\dist\node\wslDaemon.js

Replace with your current username.

By the way ${e.serverPort} is not defined anywhere

I think you found the culprit. Anyway, this workaround does also work for me! @aeschli

rivokl avatar Oct 05 '25 19:10 rivokl