WSL icon indicating copy to clipboard operation
WSL copied to clipboard

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

Open NaiveTomcat opened this issue 6 years ago • 16 comments

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 [email protected]. 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.

NaiveTomcat avatar Feb 02 '20 16:02 NaiveTomcat

This looks like a duplicate of #4860.

DHowett-MSFT avatar Feb 02 '20 19:02 DHowett-MSFT

Maybe; but the error message ("Unable to detect if server is already installed....") is different. Also the diverge is it working in Windows Terminal but not Powershell or Windows Console (aka CMD). There's no indication in #4860 that using Windows Terminal is a work-around. [If it is, that would be a good data point.]

@NaiveTomcat: please confirm whether VS Code was working for you before your Windows Update to 19555. If it was working, roll back and see if that helps. If it doesn't, then we can dig a little more. A betting person would still pin this on #4860 -- for now.

therealkenc avatar Feb 02 '20 21:02 therealkenc

Maybe; but the error message ("Unable to detect if server is already installed....") is different. Also the diverge is it working in Windows Terminal but not Powershell or Windows Console (aka CMD). There's no indication in #4860 that using Windows Terminal is a work-around. [If it is, that would be a good data point.]

@NaiveTomcat: please confirm whether VS Code was working for you before your Windows Update to 19555. If it was working, roll back and see if that helps. If it doesn't, then we can dig a little more. A betting person would still pin this on #4860 -- for now.

@therealkenc On 19551.1005, Code can successfully connect to WSL and launch wsl through Windows Console and Powershell and Start Menu succeeded. All that happened after I updated it to 19555.1001. I have deleted the previous Windows install file so I couldn't roll back to 19551.1001.

And for your information, my computer experienced update failure since 18990.1, and not untill 19551.1005 the update succeeded

NaiveTomcat avatar Feb 03 '20 04:02 NaiveTomcat

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.

therealkenc avatar Feb 03 '20 05:02 therealkenc

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.

NaiveTomcat avatar Feb 03 '20 07:02 NaiveTomcat

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.

But I experienced another bothering thing that in the task manager, Internet connection for wsl does not appear after those.

Bug need explain.

NaiveTomcat avatar Feb 03 '20 14:02 NaiveTomcat

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.

JMBBunch avatar Feb 03 '20 18:02 JMBBunch

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.

therealkenc avatar Feb 03 '20 19:02 therealkenc

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.

DHowett-MSFT avatar Feb 03 '20 19:02 DHowett-MSFT

@JMBBunch Actually, this way can only launch WSL from Powershell.

Any attempt for launching WSL from CMD and vscode fails.

NaiveTomcat avatar Feb 03 '20 19:02 NaiveTomcat

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.

@DHowett-MSFT Making PATH environmental variable crazily short did help. It was the I found out restart WSL in Powershell did help, even with a more-than-one-thousand-chracter long PATH variable.

NaiveTomcat avatar Feb 03 '20 19:02 NaiveTomcat

And I did try it and it works. But I don't want to make some of my PATH-Variable-sensitive applications got messed so I restored my PATH environmental variable

NaiveTomcat avatar Feb 03 '20 19:02 NaiveTomcat

And because I am in PRC so my online time is base on GMT+8 time zone. I may be late to reply

NaiveTomcat avatar Feb 03 '20 19:02 NaiveTomcat

This seems like literally the same error message as #4866.

It is the same as (a dupe of) #4860. The only thing keeping this submission (#4866) alive is all the thumbs up on @JMBBunch's post indicating shortening the %PATH% didn't help.

Given that @NaiveTomcat has confirmed the %PATH% work-around though, there isn't an actionable left here.

therealkenc avatar Feb 03 '20 19:02 therealkenc

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!

JMBBunch avatar Feb 03 '20 19:02 JMBBunch

Alright. I hate debouncing closes, but there is nothing novel left here. Alternative work-around remains Remote - SSH.

therealkenc avatar Feb 03 '20 19:02 therealkenc