microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.25k stars 812 forks source link

Windows commands inside WSL hang forever (dozens of seconds) #8544

Closed keai4le closed 9 months ago

keai4le commented 2 years ago

Version WSL 0.60.0.0

WSL Version WSL 2

Kernel Version 5.10.102.1

Distro Version Ubuntu 20.04.4 LTS

Other Software No response

Reproduce Steps Run any windows command in side WSL(e.g. wsl.exe --version)

Expected Behavior Can use windows commands from inside WSL (e.g. wsl.exe --version)

Actual Behavior Windows commands (e.g. wsl.exe --version) hang forever and not even Ctrl+C is able to kill them and I'm forced to close the terminal OR run "pkill wsl.exe" in a new WSL window.

This is a little bit like issue #7883, but I'm on the lastet windows insider preview:10.0.22621.160, and apply all the update for WSL

benhillis commented 2 years ago

/logs

ghost commented 2 years ago

Hello! Could you please provide more logs to help us better diagnose your issue?

To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging

Thank you!

keai4le commented 2 years ago

Hi @benhillis Please check the log, I'd like to update the issue description: NOT "hang forever" BUT "A very long time - dozens of seconds" WslLogs-2022-06-27_09-58-05.zip

I've created a feedback for this issue with the feedbackhub, it has screen record: https://aka.ms/AAhd1ld

keai4le commented 2 years ago

I found a workaround to temporary save my WSL. add a pip to the tail of every command. e.g.

wsl.exe --version | cat adb.exe shell cmd package list packages -f | cat (list all the packages in then connected android device)

And I found that any redirect command will not block the command prompt: either "|" or ">"

OneBlue commented 2 years ago

Thanks for reporting this @keai4le.

Looking at the logs I see a lot of plan9 traffic. I think this is caused by your prompt inside WSL. Can you try (which explains why the pipe is faster).

Can you try running:

PS1='simple-prompt'

Inside WSL to see if that makes a difference ?

keai4le commented 2 years ago

@OneBlue PS1='simple-prompt' seems not help for this issue.

Here is the new log I tried with set PS1 to simple-prompt

sandro:/mnt/c/Users/sandro.wan/Desktop$ PS1='simple-prompt'
simple-prompt wsl.exe --version

Also, add the | cat to the tail can workaround it: simple-prompt wsl.exe --version | cat

And more, I've tried "fish shell", it has the same issue too.

WslLogs-2022-07-06_14-32-56.zip

keai4le commented 2 years ago

Hi Dear, Anybody can help for this issue? I've update the wsl to latest preview, still not work.

OneBlue commented 2 years ago

@keai4le: Looking at the second set of logs you shared, I still see a lot of plan9 traffic. I wonder what your path variable looks like ?

Can you share the output of echo %PATH% in cmd.exe ?

Also, what do you get if you reduce the path, with something like:

path C:\windows\system32
wsl.exe

?

keai4le commented 2 years ago

@OneBlue Thanks for your investigation. But still not help when I reduce the path to only "/mnt/c/Windows/System32" Then excute wsl.exe --version

The original path variable: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/Eclipse Adoptium/jdk-17.0.3.7-hotspot/bin:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0:/mnt/c/Windows/System32/OpenSSH:/mnt/c/Program Files (x86)/NetSarang/Xshell 7:/mnt/c/Users/sandro.wan/AppData/Local/Android/Sdk/platform-tools:/mnt/c/Program Files/dotnet:/mnt/c/Program Files/Bandizip:/mnt/c/Program Files/Git/cmd:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files (x86)/Qualcomm/QXDM5:/mnt/c/Program Files (x86)/Qualcomm/PCAT/bin:/mnt/c/Program Files (x86)/Qualcomm/QUTSStatusApp:/mnt/c/Program Files (x86)/Qualcomm/QIKTool/1.0.127.1:/mnt/c/Users/sandro.wan/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/sandro.wan/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/sandro.wan/.dotnet/tools:/snap/bin:/home/sandro/.fzf/bin

Here is the new log that I reduce the path then excute "wsl.exe --version"(by export PATH=/mnt/c/Windows/System32") WslLogs-2022-07-26_13-00-54.zip

OneBlue commented 2 years ago

Interesting. So if I understand correctly, you're running wsl.exe --version from inside WSL right ?

Can you share the output of: strace -t -f wsl.exe --version ?

keai4le commented 2 years ago

Interesting. So if I understand correctly, you're running wsl.exe --version from inside WSL right ?

Yes, every command from windows(suffix with .exe OR in the windows' PATH) has this behavior.

Can you share the output of: strace -t -f wsl.exe --version ?

Please check the txt file(saved from the windows terminal): strace -t -f wsl.exe.txt

From above output, I execute the command twice. For the second, I hit the ENTER key when waiting for the result(at 23:47:58), then it block forever.

OneBlue commented 2 years ago

Interesting, so from I see in the strace, it looks wsl.exe is writing its content to stdout pretty quickly, but then takes a while to "complete".

I'm guessing that something is hanging on the Windows side, and the Linux side is just waiting for it.

Could please share process dumps of all wsl.exe, wslhost.exe and wslservice.exe when the command is in the "hung" state ?

keai4le commented 2 years ago

@OneBlue Could you please share me how to dump "wsl.exe, wslhost.exe and wslservice.exe"?

BTW, I found my disk is filled by this dir yesterday, I'm not sure if it's related to this issue. C:\Users\sandro.wan\AppData\Local\Temp\DiagOutputDir\RdClientAutoTrace (I've set this folder denide to write for all to save my disk)

OneBlue commented 2 years ago

Here are some instructions on how to create dump files from processes: https://support.kaspersky.com/common/diagnostics/12401

keai4le commented 2 years ago

@OneBlue Please help check the attached dump files. wsldumps.zip wsldumps.z01.zip wsldumps.z02.zip wsldumps.z03.zip I seperate the dump zip to 4 files because it's too large to upload, rename wsldumps.z01.zip to wsldumps.z01, etc. Then can be extracted.

keai4le commented 1 year ago

Dear @OneBlue

Sorry for bother

Any progress for this issue? I still have this problem event upgrade WSL to 1.0.0.0

WSL version: 1.0.0.0 kernel version: 5.15.74.2 WSLg version: 1.0.47 MSRDC version: 1.2.3575 Direct3D version: 1.606.4 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22623.891

Thus I msut add a "| cat" after all windows exe programs to let it return faster.

BRs.

JustAHobbyDev commented 9 months ago

Would love to see progress on this issue, but big thanks to @keai4le for the pipe trick. I'm now able to get xdg-open to work as expected.

OneBlue commented 9 months ago

@keai4le: We've made lots of fixes in WSL 2.0.0 that could fix your issue. Can you try installing it and see if you still have that behavior ?

If so please capture a /dump

keai4le commented 7 months ago

@keai4le: We've made lots of fixes in WSL 2.0.0 that could fix your issue. Can you try installing it and see if you still have that behavior ?

If so please capture a /dump

Hi @OneBlue I'm very glad to tell you that after the latest windows upgrading, this issue is fixed.

Now I'm on 23H2, 22635.3130, Windows Feature Experience Pack 1000.22685.1000.0

keai4le commented 7 months ago

WSL 版本: 2.1.1.0 内核版本: 5.15.146.1-2 WSLg 版本: 1.0.60 MSRDC 版本: 1.2.5105 Direct3D 版本: 1.611.1-81528511 DXCore 版本: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows 版本: 10.0.22635.3130