WSL: The Windows Subsystem for Linux instance has terminated.

Version

Microsoft Windows [Version 10.0.19043.1266]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

shadycuz-> wsl.exe --status
Default Distribution: Ubuntu
Default Version: 2

Windows Subsystem for Linux was last updated on 7/22/2021
WSL automatic updates are on.

Kernel version: 5.10.16

Distro Version

Ubuntu

shadycuz-> lsb_release -r
Release:        20.04

Other Software

Docker Desktop (Windows) 3.5.1 (66090) Visual Studio Code 1.61.0

Repro Steps

This is an intermittent issue that happens to me everyday but under different circumstances. The common denominator seems to be the use of vscode.

While using vscode in the wsl backend, the editor will suddenly disconnect. This is around the time that Vmmem has exhausted the 6GB of memory I have given to wsl, even though I can’t seem to see what is using the 6GB of ram. In wsl it shows very little usage. In docker desktop I will see 2/3GB if I have a running container. It seems like their is a memory leak, since I will be coding for 2 or 3 hours before the crash but not opening any new processes. Except maybe browser tabs outside of wsl.

Once wsl has crashed I can not get back into it or use docker for windows.

C:\Users\work>wsl
The Windows Subsystem for Linux instance has terminated.

C:\Users\work>wsl -l -v
  NAME                   STATE           VERSION
* Ubuntu                 Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

but I can shut it down and restart it

C:\Users\work>wsl --shutdown

C:\Users\work>wsl
[/mnt/c/Users/work]
shadycuz->

Expected Behavior

It would be nice if it gave some info about why it has shutdown so I could fix/prevent it. It would also be nice to have some detailed logs somewhere like in the WSL container or in windows? Maybe the event viewer?

Actual Behavior

wsl crashes without explanation for why/what caused it.

Diagnostic Logs

I will try and provide next time it crashes.

Update

I was working inside a container using the remote-container extension for about an hour and all seemed fine. I then used the workspace search feature in vscode to search for Class I wanted to rename in multiple files. The ram usage for my docker container grew by over 1GB and the 1 or 2GB of free ram I had in WSL using free -h -t went from around 1.5Gi available to 36Mi.

I had first noticed that the search was taking forever when it’s usually instant. Then the vscode window disconnected.

image Note: In the search it says 1 result but that is not correct.

The container that vs-code was running then disconnected with exit code 137 which is from OOM kill. I had a second wsl window open running watch free -h -t and it froze.

image

My wsl2 config:

[wsl2]
memory=6GB # Limits VM memory in WSL 2 to 4 GB
processors=3 # Makes the WSL 2 VM use two virtual processo

I wonder if making the swap bigger could prevent these crashes. I could also give more memory?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 25 (2 by maintainers)

Most upvoted comments

Me and my team have similar issue. Wsl crashes multiple times a day. I need to restart wsl and docker to work again. We are using intellij solutions, Webstorm and Phpstorm. We have standard more wsl and memory.

[wsl2]
memory=8GB   # Limits VM memory in WSL up to 8GB
processors=4 # Makes the WSL use 4 virtual processors

I tried to increase memory for wsl, it does not resolve our issues.