ECONNREFUSED with `networkingMode=VirtioProxy` and `localhostForwarding=true`
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
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
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 --shutdowndoesn't work, I need to runtaskkill /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.
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.
Same Issue. I follow the instruction from this. It didn't work.
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.
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):
-
Find the failed port in the logs (look for:
connect ECONNREFUSED 127.0.0.1:<PORT>). -
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
- 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
- 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
Solved the issue after resetting windows. Nothing else seemed to work. Did it after almost 3 years.
My workaround for VS Code WSL ECONNREFUSED Issue
If VS Code fails with repeated
ECONNREFUSEDerrors on a dynamic port (e.g.,127.0.0.1:40237):
- Find the failed port in the logs (look for:
connect ECONNREFUSED 127.0.0.1:<PORT>).- 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
- 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
- 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.tarwsl --unregister Ubuntu-22.04wsl --import Ubuntu-22.04 C:\WSL\Ubuntu-22.04 ubuntu-backup.tarIt 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 VirtualMachinePlatformDisable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-LinuxThen just reenabled them and everything worked fine. NB! You need to reinstall your libs/packages etc inside WSL
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestartEnable-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
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.
I am also facing this issue and not working for me
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?
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.
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:
- Restarting Windows
- Restarting WSL:
wsl --shutdown&wsl(from CMD) - Removing the vscode server from WSL:
rm -rf ~/.vscode-server(from WSL) - Trying to initiate the connection from WSL:
code .(from WSL) - 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.
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:
- Restarting Windows
- Restarting WSL:
wsl --shutdown&wsl(from CMD)- Removing the vscode server from WSL:
rm -rf ~/.vscode-server(from WSL)- Trying to initiate the connection from WSL:
code .(from WSL)- 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?
@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!
To find out what network mode is used by your distro, run wslinfo --networking-mode in the WSL terminal.
@microsoft/wsl-team Interesting finding: https://github.com/microsoft/vscode/issues/255211#issuecomment-3165805999
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
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
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.
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.
Unfortunately, our company uses Netskope. They recommended to use virtioproxy as it resolves their limitations.
Does the r.push work for multiple repos open?
Unfortunately, our company uses Netskope. They recommended to use virtioproxy as it resolves their limitations.
Does the
r.pushwork for multiple repos open?
yes, it does
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.
@aeschli any ETA when this will be looked at by the vscode team?
sorry unsure if you work with them or just know them.
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 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?
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
- 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 .
Workaround which works for me :
- Set the below in .wslconfig in windows
[wsl2]
networkingMode=VirtioProxy
localhostForwarding=false
-
wsl --shutdown - Connect to WSL from VSCode (It connected without any issues )
- Click on the
WSL:Ubuntuicon on the bottom left and click onClose Remote Connection.Important : Do not close VSCode ; Only click on - Close Remote Connection - Open the WSL Settings GUI app in the Networking tab turn on "localhost forwarding" and close the app .
- In VSCode that is already open connect to the WSL again (connected without any issues )
- In VSCode integrated terminal
python3 -m http.server 8000you will see the automatic port forwarding works in the ports tab . - 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 .
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 theremote.WSL.experimental.serverPortsetting?
@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
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