22

A few days ago I was working just fine with VS Code connected to WSL Ubuntu 20.04, then I did some updating on WSL, Ubuntu 20.04 LTS and VS Code and now I can not connect to WSL 20.04, and I always got those two messages, even when no folder/workspace is selected/open.

Could not fetch remote environment

Failed to connect to the remote extension host server (Error: Connection error: Unauthorized client refused.)

When I try to open a folder it shows the folder structure but it always said that: The path does not exists. And does not show any file in it but I can follow the folder structure up and down just fine.

And on the other hand if I launch WSL with an older Ubuntu 18.04 distro, it works just fine.

I imagine there is some security setting or access list that is wrong, but I can not figure it out, and web searching has not help either.

Any idea what to do to get it working again ?.

Luis Carlos Burgos
  • 328
  • 1
  • 2
  • 6

13 Answers13

41

I had the same error. And solved it by just shutting down the wsl using command

wsl --shutdown

Saurav
  • 614
  • 7
  • 13
9

Seems things got messed up with the update. Fixed it by reinstalling the Remote WSL extension: ms-vscode-remote.remote-wsl and reloading as you will be instructed to do.

Before this though, I deleted (rm -rf) the contents of /home/<your_username>/.vscode-server/ bin/ and data/

tallwithknees
  • 151
  • 1
  • 7
  • 2
    The removal of previous .vscode* directories is the most likely solution for this issue. – Luis Carlos Burgos Jan 25 '21 at 11:31
  • tried all the proposals, but nothing worked. also reinstalled the remote extensions and rm the .vscode-server as here mentioned without success. but after reseting this extension "ms-vscode-remote.vscode-remote-extensionpack" to an older version and updating the extension, it worked again. – user2405095 Dec 15 '21 at 20:49
4

Another (additional) symptom to check: Can WSL connect to the internet (eg via apt update)?

I had compressed my AppData folder, including C:\Users\<yourname>\AppData\Local\Temp and this somehow broke the connection between WSL and the outer world. Uncompressing the Temp folder solved the problem for me.

  • Search for the `%temp%` directory, go to properties -> general -> advanced -> uncheck compress contents to save disk space. I also needed a system restart but after that, it was working. – MKrup Jul 01 '21 at 09:02
4

Lowering down the version of Remote WSL extension: ms-vscode-remote.remote-wsl worked out for me.There might be some issues with the latest version.

  • Worked for me, as well. "Visual Studio Code Remote - WSL" version 0.58.4 did not work for me. 0.85.3 works for me. – Dirk R Oct 29 '21 at 15:11
3

What worked for me on Win10:

opens Ubuntu CLI -> type in code .

It'll download the VSCode server and then open VSCode itself with no errors.

I tried the same on CMD or Powershell but it didn't work.

Luis Felipe
  • 148
  • 9
1

I had the same issue, after updating the version(1.52.1). I did uninstall the ms-vscode-remote.remote-wsl and installed it again and shutdown the WSL and close the vscode. Then started the WSL and open the VS-code again solved the issue.

Vishnu KR
  • 718
  • 1
  • 8
  • 22
1

I've tried these methods but it doesn't work:

  • wsl --shutdown
  • Reinstall VScode
  • Remove .vscode-server in WSL

Finally I found the problem, the problem was with the latest version of the WSL extension, downgrading the WSL extension worked for me.

I downgraded the extension version from v0.79.5 to 0.79.4, and after reloading the window everything was back to normal.

enter image description here

enter image description here

Calos
  • 1,783
  • 19
  • 28
0

Just in case somebody else run into this problem. The way I solved was to remove all the .vscode* folders/files on the WSL filesystem. Apparently something got screw up on the upgrade.

I have not test it fully, because I moved to directly using a remote ssh agent on the Test system. But it seems to work, as I can now open the wsl window and it does not report any error.

Luis Carlos Burgos
  • 328
  • 1
  • 2
  • 6
0

I am not sure if you have read the official documentation of using WSL with VS code https://code.visualstudio.com/docs/remote/wsl

We need to run the command code . in the folder we want to open from the WSL terminal. Then it installs the vs code server on WSL.

At least in my case, vs code server was not installed.

Kitwradr
  • 1,986
  • 3
  • 18
  • 32
0
sudo apt update

shoud work fine.

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
0

I ran to the same problem today, my solution was to rollback to previous VScode version. I know there might be multiple root causes, this is one of the them.

Xiang ZHU
  • 365
  • 2
  • 13
0

powershell script that helps

# Restart LxssManager service
Restart-Service -Name LxssManager -force

# Shutdown WSL
wsl --shutdown

# Define the file paths to delete
$lockedDirectoriesPath = "C:\Users\<user>\AppData\Roaming\Docker\locked-directories"
$settingsJsonPath = "C:\Users\<user>\AppData\Roaming\Docker\settings.json"

# Delete the files if they exist
if (Test-Path $lockedDirectoriesPath) {
    Remove-Item -Path $lockedDirectoriesPath -Force
}

if (Test-Path $settingsJsonPath) {
    Remove-Item -Path $settingsJsonPath -Force
}

# Check if Docker Desktop process is running
$dockerProcess = Get-Process -Name "Docker Desktop" -ErrorAction SilentlyContinue

if ($dockerProcess) {
    # Terminate Docker Desktop Windows process
    Stop-Process -Name "Docker Desktop" -Force
}

# Start Docker Desktop app
Start-Process -FilePath "C:\Program Files\Docker\Docker\Docker Desktop.exe"
-3

Same problem, just quite the proxy software (Charles etc.) and restart the vscode, it will work fine

limi58
  • 1
  • 2
  • In my case there was no proxy software, just WSL and VSC with a bunch of extensions. – Luis Carlos Burgos Nov 05 '21 at 08:17
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30254219) – user12256545 Nov 05 '21 at 14:25