Sunday, May 26, 2024

Unresponsive WSL2 Linux Kernel Binary | How to Safely Restart

PROBLEM 

WSL2 service can become unresponsive after Microsoft Windows 11 version 21H2 recovers from a system sleep. This problem persists across warm and cold restarts.

SYMPTOMS

  • No response from Linux applications running under Win11 version 21H2.
  • No response when using wsl commands under Windows PowerShell. 
  • The VmmemWSL process appears to be consuming all spare CPU cycles. 
  • Docker Containers appear frozen, hung, or crashed. 
  • Linux Subsystem machines appear frozen, hung, or crashed. 
  • WSL2 service appears frozen, hung, or crashed.

RESOLUTION

STEP 1: Start Windows PowerShell with Administrator privileges.

STEP 2: Execute "wsl -l -v" to show the status of the installed WSL2 Linux distributions. 

Note: if WSL2 is completely unresponsive, this command will appear to stall indefinitely. If this happens, then the use of 'taskkill' in step 3 should address the problem by killing the WSL2 service and allowing a new shell to be launched. 

Restart the Administrator PowerShell and skip to STEP 3 if the following command does not respond within a few seconds.

PS C:\Users\Dj> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2
  kali-linux             Running         2

STEP 3: Execute "taskkill" as shown below to stop the WSL2 Service.

PS C:\Users\Dj> taskkill /F /im wslservice.exe
SUCCESS: The process "wslservice.exe" with PID 17856 has been terminated. 

STEP 4: Execute "wsl -l -v" to show the status of the installed WSL2 Linux distributions. If the WSL2 service was stopped successfully as a result of the previous step, the wsl commands should now become responsive. 

PS C:\Users\Dj> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Stopped         2
  docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2
  kali-linux             Stopped         2

STEP 5: Test the WSL2 Service by launching a Linux shell using your preferred method. For a quick check, simply execute "wsl" from the Windows PowerShell prompt and you should find yourself at the prompt of your default Linux distribution. 

PS C:\Users\Dj> wsl
dj@KC7ZXY-5950X:/mnt/c/Users/Dj$

STEP 6: Exit out of the Linux shell, and then execute "wsl -l -v" back at the Windows PowerShell prompt, as shown below, to list the status of the installed WSL2 Linux distributions.

dj@KC7ZXY-5950X:/mnt/c/Users/Dj$ exit
logout

PS C:\Users\Dj> wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2
  kali-linux             Stopped         2

STEP 7: If you have reached this point and were able to execute the wsl commands and get the Linux kernel running again, breathe easy and relax. …then grab another coffee (or any other favorite beverage) and go do all the things!

CONCLUSION

While the root cause is not yet known to me, the WSL2 service can become unresponsive after the system recovers from a system sleep. Using the tools provided within Windows PowerShell, the status of the Linux binaries can be inspected and the WSL2 service can be restarted when necessary.