WSL: VS Code couldn't link with wsl2 and cannot open wsl2 through powershell or cmd

Please use the following bug reporting template to help produce issues which are actionable and reproducible, including all command-line steps necessary to induce the failure condition. Please fill out all the fields! Issues with missing or incomplete issue templates will be closed.

If this is a console issue (a problem with layout, rendering, colors, etc.), please post to the console issue tracker.

Important: Do not open GitHub issues for Windows crashes (BSODs) or security issues. Please direct all Windows crashes and security issues to secure@microsoft.com. Ideally, please configure your machine to capture minidumps, repro the issue, and send the minidump from "C:\Windows\minidump".\

See our contributing instructions for assistance.

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt)

Microsoft Windows [版本 10.0.19555.1001]

  • What you’re doing and what’s happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

In powershell

PS C:\Users\12045> wsl.exe -d Ubuntu
由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

In VS Code

image

  • What’s wrong / what should be happening instead:

I am using wsl2, and wsl2 is working properly and can be access through Windows Terminal. But when I attemp to launch wsl by typing wsl.exe in cmd or powershell prompt, connection failed.

Problem also occers when I try to run VS Code Terminal with wsl.

In addition, Windows Terminal and PuTTY ssh connected seccessfully.

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here).

  • For WSL launch issues, please collect detailed logs.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 16

Most upvoted comments

In Powershell 6: (LOL the editor keeps eating my brackets. LOL)

$Env:PATH="C:\Users\username\AppData\Local\Microsoft\WindowsApps;C:\Users\username\AppData\Local\Programs\Microsoft VS Code\bin;"

Then:

C:\windows\system32\wsl.exe

At that point I get the expected WSL prompt, sitting at /mnt/c/WINDOWS/system32. At that prompt I run: code .

Voila! VS Code opens a terminal sitting at /mnt/c/WINDOWS/system32. From there, I can get access to the WSL homedir ~. Yay!

Can you try… (from PowerShell)

$Env:PATH=""
& C:\windows\system32\wsl.exe

?

Thanks.

FWIW: The translation of the error message “由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。” is … “The connection attempt failed because the connecting party did not respond correctly after a period of time or the connected host did not respond.” This seems like literally the same error message as #4866.

To be clear, my WSL now starts fine after shortening the path

Great. Thanks for the confirmation (the OP had not).

but I still can’t get VS Code to access WSL.

[ed] Rather than dupe (with an overabundance of caution) we can hold this open for a bit until the VS Code “Unable to detect...” fail is resolved by a rollback.

I may have found a way to overcome this bug

Type wsl --shutdown in the Powershell and wsl again in the powershell to restart wsl and then, it started working dramatically.

This way only applies to Powershell, VS Code and Command Prompt still can’t launch wsl.

This did not help. Exact same messages within VS Code.
To be clear, my WSL now starts fine after shortening the path, but I still can’t get VS Code to access WSL.

Alright. That leaves a couple of options. (1) Sit on it until the #4860 fix rolls out. (2) Attempt work-arounds. The canonically accepted work-around (other than rolling back) being launder your path to something crazy short. For example:

image

However there are good indications that doesn’t work for your particular fail.

The other work-around is to use Remote - SSH.

Given you were okay on 19551 but not 19555, this near certain has to be a dupe root cause (working premise anyway). But we can hold this submission standalone until your and @JMBBunch’s scenario has a confirmed work-around short of rollback.