Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winsock module breaks WSL2 #4177

Closed
Librazy opened this issue Jun 18, 2019 · 95 comments
Closed

Winsock module breaks WSL2 #4177

Librazy opened this issue Jun 18, 2019 · 95 comments
Assignees
Labels
wsl2 Issue/feature applies to WSL 2

Comments

@Librazy
Copy link

Librazy commented Jun 18, 2019

For an workaround provided by Proxifier, see #4177 (comment)

Please fill out the below information:

  • Your Windows build number: 10.0.18917.1000

  • What you're doing and what's happening:
    After updating from 1903 to 18917, I upgraded to WSL2 and it works fine. Later, I enabled https://www.proxifier.com/'s winsock module in its "System Setting 64-bit" app, and WSL2 starting to fail with The attempted operation is not supported for the type of object referenced..

⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl
The attempted operation is not supported for the type of object referenced.
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl -l -v
NAME            STATE           VERSION
* Ubuntu-18.04    Running         2
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl --shutdown 
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl -l -v 
NAME            STATE           VERSION
* Ubuntu-18.04    Stopped         2
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl
The attempted operation is not supported for the type of object referenced.
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl -l -v
NAME            STATE           VERSION
* Ubuntu-18.04    Running         2
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl -l -v
NAME            STATE           VERSION
* Ubuntu-18.04    Stopped         2
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl
The attempted operation is not supported for the type of object referenced.
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl -l -v
NAME            STATE           VERSION
* Ubuntu-18.04    Running         2
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl
The attempted operation is not supported for the type of object referenced.

After uninstalling the winsock module, WSL2 launches again. And installing the winsock module won't cause running WSL2 console to fail.

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

WSL2 should work even if there are other winsock modules installed.

lxcore.zip

@benhillis
Copy link
Member

Thanks for providing a trace, I will take a look.

@benhillis
Copy link
Member

benhillis commented Jun 19, 2019

I took a look at the trace and I'm not seeing any relevant events in the service etl. If possible could you do the following?

wsl.exe --shutdown
start trace
launch distribution
stop trace

@benhillis benhillis added the wsl2 Issue/feature applies to WSL 2 label Jun 19, 2019
@Librazy
Copy link
Author

Librazy commented Jun 20, 2019

Steps I take (In a Chinese environment)
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ wsl.exe --shutdown
⚡ Liqueur Librazy C:\..\system32 ❯❯❯ cd 'C:\Users\Liqueur Librazy\OneDrive\桌面\'
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯ logman.exe create trace lxcore_kernel -p "{0CD1C309-0878-4515-83DB-749843B3F5C9}" -mode 0x00000008 -ft 10:00 -o .\lxcore_kernel.etl -ets                                                                       命令成功结束。
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯ logman.exe create trace lxcore_user -p "{D90B9468-67F0-5B3B-42CC-82AC81FFD960}" -ft 1:00 -rt -o .\lxcore_user.etl -ets                                                                                         命令成功结束。
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯ logman.exe create trace lxcore_service -p "{B99CDB5A-039C-5046-E672-1A0DE0A40211}" -ft 1:00 -rt -o .\lxcore_service.etl -ets                                                                                   命令成功结束。
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯ wsl                                                                                    参考的对象类型不支持尝试的操作。
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯ logman.exe stop lxcore_kernel -ets
命令成功结束。
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯ logman.exe stop lxcore_user -ets
命令成功结束。
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯ logman.exe stop lxcore_service -ets
命令成功结束。
⚡ Liqueur Librazy ~\..\桌面 ❯❯❯

lxcore.zip

@xiaoqidun
Copy link

xiaoqidun commented Jun 27, 2019

same question,proxifier winsock installation,wsl2 can not work.

@yeahnoob
Copy link

Same issue of WSL 2 on my Win10 laptop.

@sticnarf
Copy link

Sorry for a useless comment.
Developers in China highly rely on proxies due to poor network condition. I do hope this issue will be resolved soon.

@SwimmingTiger
Copy link

SwimmingTiger commented Jul 3, 2019

The same issue. After running a game speedup VPN (https://uu.163.com), WSL2 cannot running.
Reset winsock can fix it.

PS C:\WINDOWS\system32> wsl.exe --shutdown
PS C:\WINDOWS\system32> wsl.exe
The attempted operation is not supported for the type of object referenced.
PS C:\WINDOWS\system32> netsh winsock reset

Sucessfully reset the Winsock Catalog.
You must restart the computer in order to complete the reset.

PS C:\WINDOWS\system32> wsl.exe
root@TIGERHOMEPC /mnt/c/Windows/System32
  # exit

Build 18922.1000.

@Librazy Librazy changed the title "Proxifier" breaks WSL2 if its Winsock module is installed Winsock module breaks WSL2 Jul 4, 2019
@infdahai
Copy link

infdahai commented Jul 5, 2019

The same issue. After running a game speedup VPN (https://uu.163.com), WSL2 cannot running.
Reset winsock can fix it.

PS C:\WINDOWS\system32> wsl.exe --shutdown
PS C:\WINDOWS\system32> wsl.exe
The attempted operation is not supported for the type of object referenced.
PS C:\WINDOWS\system32> netsh winsock reset

Sucessfully reset the Winsock Catalog.
You must restart the computer in order to complete the reset.

PS C:\WINDOWS\system32> wsl.exe
root@TIGERHOMEPC /mnt/c/Windows/System32
  # exit

Build 18922.1000.

I encounter this problem and use this method to solve. But my proxifier can't be used.

@nimocat
Copy link

nimocat commented Jul 10, 2019

So the problem is, after using any kinds of vpn (such as shadowsocks or whatever), wsl2 will crash when users try to start it. So I think it needs to be compatible with vpns in the future.

@Librazy
Copy link
Author

Librazy commented Jul 22, 2019

Still reproducible on recent insider versions

@xiaoqidun
Copy link

xiaoqidun_2019-07-23_10-12-16
windows10 18941.1001,this problem is still not fixed。

@Librazy
Copy link
Author

Librazy commented Jul 29, 2019

Still relevant. 10.0.18945.1001

@wrvsrx
Copy link

wrvsrx commented Aug 1, 2019

The problem exists on build 18950.1000.
update: 18956.1000, still here

@zookao
Copy link

zookao commented Aug 12, 2019

still 18956

@xiaoqidun
Copy link

windows10 18956.1000,this problem is still not fixed。

@Librazy
Copy link
Author

Librazy commented Aug 18, 2019

reproducible in 18963

@JaylonGu
Copy link

18963.1000,this problem is still not fixed。

@DDoSolitary
Copy link

I don't think it makes any sense to keep reporting the bug is still not fixed, because there hasn't been any claim from Microsoft that it's fixed. It's pretty obvious that the issue is universal and easily reproducible, and it's very likely that Microsoft is already aware of it. So such comments only spam this issue and and the email inbox of those who have subscribed to this issue.

@benhillis
Copy link
Member

I took a look at the traces and unfortunately there really isn't much to go on other than WSAEOPNOTSUPP being returned when trying to call into the Service com interface. There are no errors originating from our service itself, so I suspect something outside of WSL components is causing the issue.

For people that are hitting this issue, I would suggest looking in the Windows event log or using https://docs.microsoft.com/en-us/sysinternals/downloads/procmon to help track down what is returning the error. Honestly this seems like an error in https://www.proxifier.com/

@Librazy
Copy link
Author

Librazy commented Aug 21, 2019

As many other winsock modules breaks wsl2, I think it is not Proxifier's fault. It is likely that the communication between wsl2 and other components (likely hyperv?) is broken.

I captured events from wsl.exe using procmon when reproducing the issue
Logfile.zip

And there are the windows event logs (system)
wsl4177.evtx.zip

@benhillis
Copy link
Member

@Librazy - Thanks for the additional logs. Unfortunately as I mentioned before, wsl.exe is not where the errors are coming from. I suspect proxifier and other winsock modules are not correctly handling the Hyper-V socket address family (AF_HYPERV). I would strongly suggest reporting the issue to them.

@craigloewen-msft
Copy link
Member

If you're still seeing this error, could you help us diagnose it by collecting networking logs?

Instructions on how to do so are here. Thanks!

@Librazy
Copy link
Author

Librazy commented Sep 7, 2019

@craigloewen-msft Thanks for the instructions and here is the log! https://aka.ms/AA5zzk7

@benhillis
Copy link
Member

@craigloewen-msft - I am not seeing logs attached to @Librazy's feedback hub issue. Can you investigate?

@craigloewen-msft
Copy link
Member

@benhillis Yup! I'll look into it.

@lingsamuel
Copy link

lingsamuel commented Dec 4, 2022

Instead of C:\windows\system32\wsl.exe, the new path is under windows apps, which for me is C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wsl.exe (you can find the path by Everything or Task Manager). You may also need to add wslservice.exe.

(I am not sure all of these are needed. I just add all paths I found in task manager)

# version 2.0.4
NoLsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_2.0.4.0_x64__8wekyb3d8bbwe\wsl.exe"

# some new path in 2.0.4
NoLsp.exe "C:\Program Files\WSL\wsl.exe"
NoLsp.exe "C:\Program Files\WSL\wslservice.exe"
NoLsp.exe "C:\Program Files\WSL\wslhost.exe"
NoLsp.exe "C:\Program Files\WSL\wslrelay.exe"

# some old path found in task manager
NoLsp.exe "C:\Windows\System32\wsl.exe"

If you don't want to reboot, use taskkill -IM "wslservice.exe" /F to kill all wsl stuff.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\04C4CA21]
"AppFullPath"="C:\\Program Files\\WindowsApps\\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\\wsl.exe"
"PermittedLspCategories"=dword:80000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\0E1558B0]
"AppFullPath"="C:\\Program Files\\WindowsApps\\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\\wslservice.exe"
"PermittedLspCategories"=dword:80000000

@yuxi-liu-wired
Copy link

How I managed to solve the problem:

> cd "C:\Program Files\WindowsApps\"

Search for some folder that looks like "MicrosoftCorporationII.WindowsSubsystemForLinux ... x64 ...". For me, it was "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe"

Go in and list its files. It should contain "wsl.exe" and "wslservice.exe".

Download https://web.archive.org/web/20220728095911/http://www.proxifier.com/tmp/Test20200228/NoLsp.exe

Open a windows terminal with admin priviledge.

Kill WSL with
> taskkill -IM "wslservice.exe" /F

Run NoLsp.exe on both "wsl.exe" and "wslservice.exe". For me, it was like
> .\NoLsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wsl.exe"

> .\NoLsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wslservice.exe"

@mamhadu
Copy link

mamhadu commented Dec 12, 2022

How I managed to solve the problem:

> cd "C:\Program Files\WindowsApps\"

Search for some folder that looks like "MicrosoftCorporationII.WindowsSubsystemForLinux ... x64 ...". For me, it was "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe"

Go in and list its files. It should contain "wsl.exe" and "wslservice.exe".

Download https://web.archive.org/web/20220728095911/http://www.proxifier.com/tmp/Test20200228/NoLsp.exe

Open a windows terminal with admin priviledge.

Kill WSL with
> taskkill -IM "wslservice.exe" /F

Run NoLsp.exe on both "wsl.exe" and "wslservice.exe". For me, it was like
> .\NoLsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wsl.exe"

> .\NoLsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wslservice.exe"

I have Windows 11 21H2 and added the following to registry and it doesn't work :(

Two entries are created:

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\04C4CA21
AppFullPath C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wsl.exe

and

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\0E1558B0
AppFullPath C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\wslservice.exe

both with PermittedLspCategories 80000000

@fanthos
Copy link

fanthos commented Dec 14, 2022

The store version path of wsl.exe and wslservice.exe changes every version WSL released on store, so I have to manually add registry entries and reboot my computer every time WSL updated, to make WSL2 and my VPN client works together.

For 1.0.3.0:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\04FC3F2F]
"AppFullPath"="C:\\Program Files\\WindowsApps\\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.3.0_x64__8wekyb3d8bbwe\\wsl.exe"
"PermittedLspCategories"=dword:80000000

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\12AF910F]
"AppFullPath"="C:\\Program Files\\WindowsApps\\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.3.0_x64__8wekyb3d8bbwe\\wslservice.exe"
"PermittedLspCategories"=dword:80000000

@florentinadolf
Copy link

can confirm that the solution @lingsamuel posted #4177 (comment)
is working

@JerryChen97
Copy link

Thank you! This is very important. My previous reg file also didn't work because of the version change

@yzc-sky
Copy link

yzc-sky commented Dec 16, 2022

can confirm that the solution @lingsamuel posted #4177 (comment) is working

don't work still

@mariotaku
Copy link

There are some caveats for NoLsp.exe.

  1. Full path must be specified. It doesn't check if wsl.exe exists or not.
  2. Every time Microsoft Store version WSL updates, you'll need to run it manually.

So I created this script to run on boot. I have tested and now it works without issue. (Please remember to kill wslservice.exe if it doesn't work)

#Requires -RunAsAdministrator
# Fix for https://github.com/microsoft/WSL/issues/4177

$MethodDefinition = @'
[DllImport("ws2_32.dll", CharSet = CharSet.Unicode)]
public static extern int WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, out uint pPrevPermLspCat, out int lpErrno);
'@

$Ws2Spi = Add-Type -MemberDefinition $MethodDefinition -Name 'Ws2Spi' -PassThru

$WslLocation = Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux | Select-Object -expand InstallLocation

$Executables = ("wsl.exe", "wslservice.exe");

foreach ($Exe in $Executables) {
    $ExePath = "${WslLocation}\${Exe}";
    $ExePathLength = $ExePath.Length;

    $PrevCat = $null;
    $ErrNo = $null;
    if ($Ws2Spi::WSCSetApplicationCategory($ExePath, $ExePathLength, $null, 0, [uint32]"0x80000000", [ref] $PrevCat, [ref] $ErrNo) -eq 0) {
        Write-Output "Added $ExePath!";
    }
}

@RichardDavies
Copy link

@mariotaku Out of curiosity, how do you run this script as an Administrator on boot up?

@fanthos
Copy link

fanthos commented Jan 12, 2023

@mariotaku Out of curiosity, how do you run this script as an Administrator on boot up?

Windows Task Scheduler

@mariotaku
Copy link

@mariotaku Out of curiosity, how do you run this script as an Administrator on boot up?

When I add it to the task scheduler, I configured it to use the highest privilege.

@wtto00
Copy link

wtto00 commented Feb 14, 2023

如果应用商店安装了Windows Subsystem for Linux

  1. 首先找到安装位置,最简单的方法是,打开应用商店,找到应用Windows Subsystem for Linux,点击应用详细介绍页面的打开按钮,会新打开一个terminal窗口,窗口的标题上面有所安装的wsl.exe的全路径。

    或者也可以手动搜索,由于目录C:\Program Files\WindowsApps是保护文件夹,没法直接在资源管理器中搜索,可以管理员打开powershell

    cd "C:\Program Files\WindowsApps"
    ls

    找到对应版本的wsl目录,例如MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe

  2. 下载nolsp.exe

  3. 管理员打开powershell,执行以下命令:

    # 打开nolsp.exe所在目录
    cd E:\Downloads\Other\nolsp.exe
    
    # 该步骤就相当于添加注册表
    .\nolsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wsl.exe"
    .\nolsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wslservice.exe"
    # 注意:这里的wsl.exe以及wslservice.exe,必须是全路径,不能是相对路径。

    打开注册表regedit,找到\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog,依次点击此目录的各项,可以找到两项:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\2BB0D7FB]
    "AppFullPath"="C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wsl.exe"
    "PermittedLspCategories"=dword:80000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\2FB92E99]
    "AppFullPath"="C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wslservice.exe"
    "PermittedLspCategories"=dword:80000000
    

至此,就可以打开wsl了。
如果商店更新了Windows Subsystem for Linux,需要重新执行一遍此流程


如果应用商店没有安装了Windows Subsystem for Linux

直接在注册表regedit添加项即可:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\0408F7A3]
"AppFullPath"="C:\Windows\System32\wsl.exe"
"PermittedLspCategories"=dword:80000000

临时解决办法:

管理员打开powershell,运行netsh winsock reset,不用重启,就可以打开wsl了。
但是每次重新启动电脑时,都要重新运行一次此流程。

@fjh1997
Copy link

fjh1997 commented Feb 25, 2023

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\

原来是自动的,我之前还费劲去手动添加注册表呢。如果termit报错0x8007273d 还需要这样。

.\nolsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wslg.exe"
#如果还不行可能要添加wslhost.exe
.\nolsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wslhost.exe"

@lm902
Copy link

lm902 commented Mar 28, 2023

Still reproducable in year 2023. The solution is already provided in comments, not sure why its still not fixed.
Windows 11 build 22621.1413

@pnck
Copy link

pnck commented Apr 7, 2023

如果应用商店安装了Windows Subsystem for Linux

  1. 首先找到安装位置,最简单的方法是,打开应用商店,找到应用Windows Subsystem for Linux,点击应用详细介绍页面的打开按钮,会新打开一个terminal窗口,窗口的标题上面有所安装的wsl.exe的全路径。

    或者也可以手动搜索,由于目录C:\Program Files\WindowsApps是保护文件夹,没法直接在资源管理器中搜索,可以管理员打开powershell

    cd "C:\Program Files\WindowsApps"
    ls

    找到对应版本的wsl目录,例如MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe

  2. 下载nolsp.exe

  3. 管理员打开powershell,执行以下命令:

    # 打开nolsp.exe所在目录
    cd E:\Downloads\Other\nolsp.exe
    
    # 该步骤就相当于添加注册表
    .\nolsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wsl.exe"
    .\nolsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wslservice.exe"
    # 注意:这里的wsl.exe以及wslservice.exe,必须是全路径,不能是相对路径。

    打开注册表regedit,找到\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog,依次点击此目录的各项,可以找到两项:

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\2BB0D7FB]
    "AppFullPath"="C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wsl.exe"
    "PermittedLspCategories"=dword:80000000
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\2FB92E99]
    "AppFullPath"="C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.1.2.0_x64__8wekyb3d8bbwe\wslservice.exe"
    "PermittedLspCategories"=dword:80000000
    

至此,就可以打开wsl了。 如果商店更新了Windows Subsystem for Linux,需要重新执行一遍此流程

如果应用商店没有安装了Windows Subsystem for Linux

直接在注册表regedit添加项即可:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WinSock2\Parameters\AppId_Catalog\0408F7A3]
"AppFullPath"="C:\Windows\System32\wsl.exe"
"PermittedLspCategories"=dword:80000000

临时解决办法:

管理员打开powershell,运行netsh winsock reset,不用重启,就可以打开wsl了。 但是每次重新启动电脑时,都要重新运行一次此流程。

This workaround must be applied every time after the wsl app (app store version) updated, since the versioned path keeps changing. But it's hard to tell when or even whether the app was updated. So ... still quite a mess.

@wtto00
Copy link

wtto00 commented Apr 7, 2023

@pnck
Attempted to change the WSL startup command from C:\WINDOWS\system32\wsl.exe -d Ubuntu-20.04 to just bash.
Yes, that's right, just one word: bash. It worked for me.

Alternatively, you could try downloading and installing a different Linux distribution from the Microsoft Store, such as Ubuntu 22.04 LTS. I have tried this myself and it also works.

@t1hq
Copy link

t1hq commented Jul 8, 2023

heroes who are digging to this issue, let me summarize the problem for you:

  • if you're having issue launching docker, or wsl, AND you're using proxy app the same time, you may encounter this problem, the wsl won't launch.
  • this is probably your proxy app is using lsp to take control of wsl network automatically for convenience(my guess), which is deprecated already since windows 8, but wsl does not support this, and it will not be fixed, so we're having this issue for years.
  • one recommended work-around is to use @mariotaku 's script to add wsl entry to your registry.
  • run the exe as admin is not recommended, an anonymous exe should not be trusted for security concern.

but if you're curious about how the appid catagory hash is decided (as i do), here's a demo to show how the hash is calculated,so you can write code to do the job for yourself, completely independent to ws2_32.dll, here's some note for the demo:

  • the path is using wide char.
  • the drive letter is ignored.
  • path capitalized during hash calculation
  • L'\0' should not be calculated, if you're using c string.

case close, studied this for a week.

@RichardDavies
Copy link

My computer updated to WSL 2.0.9.0 today and this broke again. I had previously set up the Powershell script mentioned in #4177 (comment) but that wasn't fixing it this time. I had to use NoLsp.exe again and run the following commands to get it working again:

taskkill -IM "wslservice.exe" /F
NoLsp.exe "C:\Program Files\WSL\wsl.exe"
NoLsp.exe "C:\Program Files\WSL\wslservice.exe"
NoLsp.exe "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_2.0.9.0_x64__8wekyb3d8bbwe\wsl.exe"

@rbcb-bedag
Copy link

rbcb-bedag commented Nov 22, 2023

@RichardDavies Thank you, worked for me.
I have used @mariotaku script successfully until now, but i also needed to execute NoLsp.exe.

Here is a adjusted script, that first executes the NoLsp.exe and afterwards the registry fix:

#Requires -RunAsAdministrator
# Fix for https://github.com/microsoft/WSL/issues/4177

$MethodDefinition = @'
[DllImport("ws2_32.dll", CharSet = CharSet.Unicode)]
public static extern int WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, out uint pPrevPermLspCat, out int lpErrno);
'@

$Ws2Spi = Add-Type -MemberDefinition $MethodDefinition -Name 'Ws2Spi' -PassThru

$WslLocation = Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux | Select-Object -expand InstallLocation

# Specify paths to all wsl locations

#since WSL Version 2.X.Y.Z also neccessary to execute fix in the "Program Files" locations https://github.com/microsoft/WSL/issues/4177#issuecomment-1817216126
$WslLocations = @(
    (Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux | ForEach-Object { $_.InstallLocation }),
    "C:\Program Files\WSL"
)

$Executables = ("wsl.exe", "wslservice.exe", "wslg.exe", "wslhost.exe");

foreach ($WslLocation in $WslLocations) {
	
    Write-Output "Looping trough path:  $WslLocation";
    Write-Output "==========================================";
	
    foreach ($Exe in $Executables) {
        $ExePath = Join-Path $WslLocation $Exe
		
	# Test if exe exists in the path (not all exe's are in all locations)
	if (-not (Test-Path $ExePath -PathType Leaf)) {
		Write-Output "Path not found:  $ExePath!";
		continue;
	}
				
	# First execute NoLsp.exe fix
        & ".\NoLsp.exe" $ExePath
		
	# Second execute registry fix
	$ExePathLength = $ExePath.Length;
        $PrevCat = $null;
        $ErrNo = $null;
		
        if ($Ws2Spi::WSCSetApplicationCategory($ExePath, $ExePathLength, $null, 0, [uint32]"0x80000000", [ref] $PrevCat, [ref] $ErrNo) -eq 0) {
            Write-Output "Added $ExePath!";
        }
    }
    Write-Output "";
}

I'm running this script as suggested above with highest priviliges via the Task Scheduler on every startup.
The NoLsp.exe needs to be in the same folder as this script.

Tested with WSL 2 v2.0.9.0 and ProxyCap 5.38

@rosembergramiro
Copy link

@RichardDavies Thank you, worked for me. I have used @mariotaku script successfully until now, but i also needed to execute NoLsp.exe.

Here is a adjusted script, that first executes the NoLsp.exe and afterwards the registry fix:

#Requires -RunAsAdministrator
# Fix for https://github.com/microsoft/WSL/issues/4177

$MethodDefinition = @'
[DllImport("ws2_32.dll", CharSet = CharSet.Unicode)]
public static extern int WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, out uint pPrevPermLspCat, out int lpErrno);
'@

$Ws2Spi = Add-Type -MemberDefinition $MethodDefinition -Name 'Ws2Spi' -PassThru

$WslLocation = Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux | Select-Object -expand InstallLocation

# Specify paths to all wsl locations

#since WSL Version 2.X.Y.Z also neccessary to execute fix in the "Program Files" locations https://github.com/microsoft/WSL/issues/4177#issuecomment-1817216126
$WslLocations = @(
    (Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux | ForEach-Object { $_.InstallLocation }),
    "C:\Program Files\WSL"
)

$Executables = ("wsl.exe", "wslservice.exe", "wslg.exe", "wslhost.exe");

foreach ($WslLocation in $WslLocations) {
	
    Write-Output "Looping trough path:  $WslLocation";
    Write-Output "==========================================";
	
    foreach ($Exe in $Executables) {
        $ExePath = Join-Path $WslLocation $Exe
		
	# Test if exe exists in the path (not all exe's are in all locations)
	if (-not (Test-Path $ExePath -PathType Leaf)) {
		Write-Output "Path not found:  $ExePath!";
		continue;
	}
				
	# First execute NoLsp.exe fix
        & ".\NoLsp.exe" $ExePath
		
	# Second execute registry fix
	$ExePathLength = $ExePath.Length;
        $PrevCat = $null;
        $ErrNo = $null;
		
        if ($Ws2Spi::WSCSetApplicationCategory($ExePath, $ExePathLength, $null, 0, [uint32]"0x80000000", [ref] $PrevCat, [ref] $ErrNo) -eq 0) {
            Write-Output "Added $ExePath!";
        }
    }
    Write-Output "";
}

I'm running this script as suggested above with highest priviliges via the Task Scheduler on every startup. The NoLsp.exe needs to be in the same folder as this script.

Tested with WSL 2 v2.0.9.0 and ProxyCap 5.38

I spent days struggling with it and now it's working again. Thanks!

@rbcb-bedag
Copy link

rbcb-bedag commented Dec 6, 2023

@craigloewen-msft @OneBlue
Hey guys
I saw the AMA and your help to fix the issue #10812.
So i hope you might also help us here out :D.

The summary of this issue (iirc):
It seems that some proxy tools (like proxifier or proxycap) interfere with the socket communication between the wsl instance and the host.
The solution for this was at the begining to "deactivate"/"unload" a DLL called "Lsp" from the wsl.exe.
For that, proxifier has build a small tool called NoLsp.exe, which did this "unloading" of the lsp dll.

Then the changed happened, that wsl gets automatically updated from the windows store.
After this, I had to execute the NoLsp.exe fix after every update (because every update had a new wsl.exe in an other path)
AND additionaly also had to do some registry fix.

To somehow automate this fixes, i've used successfully @mariotaku script (#4177 (comment)) and adjusted it, so that also the NoLsp.exe fix was executed.
This worked for me since January 2023 until now til WSL v1.2.5.

Since the last WSL Update (2.0.X.Y) i also had to execute the fix at the wsl.exe, that's in "Program Files" Folder, in addition to the Microsoft Store Location. (The script automaticaly find's the path to the wsl.exe's that are updated by the Microsoft Store).
Here is the complete script : #4177 (comment)

Now everything is working again fine.
I can't find any more the official link to the NoLsp.exe, but here is the one from the wayback machine: https://web.archive.org/web/20220728095911/http://www.proxifier.com/tmp/Test20200228/NoLsp.exe
I think the NoLsp.exe does only a registry entry, to unload the dll and therefore this fix could also be done without the .exe
(Maybe somone can post the manual registry fix).

My complete setup is :

  • ProxyCap 5.38
  • Citrix Secure Acces 22.10.1.9 (for VPN)
  • WSL vpn-kit (without it, i don't have internet acces inside the wsl instance)

tldr:
Would it be possible to remove this Lsp DLL from WSL AND also implement the second registry fix in an upcoming WSL Update ?
I don't know for what this DLL is, but everything is working fine without it.
Or make it an wsl config, so that we need to opt in for this fix.

Thanks in advance for your help !

P.S. the new wsl config options (networkingMode, dnsTunneling etc.) didn't helped for this problem.
The problem lies in the proxy tools, that they interferece the socket communication and can be fixed by the lsp fix

@benhillis
Copy link
Member

Fixed with https://github.com/microsoft/WSL/releases/tag/2.1.0

@rbcb-bedag
Copy link

Can confirm ProxyCap is now working with WSL 2.1.0 without any fixes.
This is great, thank you very much !!!

@rbcb-bedag
Copy link

rbcb-bedag commented Jan 9, 2024

I'm also using a VPN (Citrix Secure Access).

And now with the automatic enablement auf DNS tunneling in 2.1.0, i now don't have internet/intranet access inside the wsl.
The fix for me is now to disable that via the .wslconfig file, e.g.

[wsl2]
dnsTunneling=false

And internet/intranet access works again.

P.S. i need to use the wsl-vpnkit for that.
In theory dnsTunneling and networkMode=mirrored should do the trick, but sadly it doesn't work.
But maybe this is a specifc issue with the Citrix Secure Access Client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wsl2 Issue/feature applies to WSL 2
Projects
None yet
Development

No branches or pull requests