Vscode cannot connect to remote Linux (_WebSocket close with status code 1006)

Viewed 11585

Remote connection to Linux. After entering the password, there are two prompts on the right

11

And the terminal cannot input
The remote directory could not be loaded

I had tried countless times in many ways Reinstall vocode,delete ~/.vscode-server/ directory, and so on.
What the hell should I do.

22

9 Answers
  1. Find out which instance of WSL is running
wsl -l --running
  1. Terminate all running instances of WSL
wsl --shutdown
  1. Then simply restart WSL
wsl 

This can be resolved by rebooting the host machine (i.e. reboot your Windows PC) and restarting your WSL-2 box, then launching VSCode remote again.

No idea why this happens but from time to time I experience this issue.

Confirmed issue on:

Ubuntu 20.04
Vs code 1.60.1

I changed the setting remote.WSL.server.connectThroughLocalhost (Settings -> Extensions -> Remote - WSL -> Connect Through Localhost) from disabled to enabled, and that fixed the issue for me.

No idea why this happened in the first place though, it was working fine without enabling this setting for over 2 months, and then suddenly it stopped working.

Maybe the IP of the virtual machine changed in some unexpected way?

If anyone else comes across this question it's very easy.

  1. You're most likely using a reverse proxy
  2. Just enable websocket support on your reverse proxy.

Ex. If you are using Docker and the popular NGINX Proxy Manager; when you are adding a proxy host make sure to choose websocket support

No more 1006 error :)

Just clean up the /root/.vscode-server directory, vs code will create a new one when you connect again to the remote machine.

I had this issue as well. I used @thnee's solution of changing the connection method. I found this easiest to do by using the settings UI > Remote > Connection Method

I think that may cause by the conflict between ~/.ssh/config and ~/.ssh/known_hosts. I delete the ~/.ssh/known_hosts file and try again, find that the vscode can connect to remote successly

I have this issue all of a sudden and after a few trials, I found install another distro using WSL-1 fixes the problem. You can safely unregister the new distro afterwards.

Related