docker / for-win

Bug reports for Docker Desktop for Windows
https://www.docker.com/products/docker#/windows
1.87k stars 291 forks source link

"docker context ls" leaves behind zombie processes #14027

Open lukas-lang opened 7 months ago

lukas-lang commented 7 months ago

Description

Related to https://github.com/docker/for-win/issues/13923 and https://github.com/rancher-sandbox/rancher-desktop/issues/6451

Running docker context ls --format "{{json .}}" (as is done e.g. by the VS Code Dev containers extension) leaves behind a zombie process that is never cleaned up. This leads to a loss of available RAM & causes the system process to use a lot of CPU (due to all the page table entries).

Some observations:

Reproduce

  1. Run docker context ls --format "{{json .}}" a bunch of times (docker engine is not running in my case)
  2. Observe how the number of zombie handles goes up by approximately 3x-5x (depending on how it's run) number of calls to docker

Expected behavior

The processes should be cleaned up

docker version

Client:
 Cloud integration: v1.0.35+desktop.11
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:13:02 2024
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.28.0 (139021)
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:14:25 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    25.0.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1-desktop.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.6-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.24
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.22
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.0.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.5.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 3
 Server Version: 25.0.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
 Kernel Version: 5.15.146.1-microsoft-standard-WSL2
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 30.27GiB
 Name: docker-desktop
 ID: 3861acb3-ccc4-48dc-a7b1-718eaa00ea5d
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile

Diagnostics ID

096291B3-D04B-4013-8FAF-A02527A5E4CB/20240421192036

Additional Info

No response

lukas-lang commented 7 months ago

Update: After some more debugging, I am now more confused than ever: It looks like the problem might after all not be specific to Docker, but rather a general issue on my system, i.e. starting any application will leave behind a zombie process. I will need to investigate further once I find some more time. In the meantime, any insights would of course be greatly appreciated

totoguy commented 6 months ago

@lukas-lang I've been having the exact same experience - thousands and thousands of zombie processes, ram getting eaten up, system process constantly around 5-15%, etc.

Pretty much ran all the tests you have, on RamMap + WPR, and reached the same results as in your screenshots. Only difference is the symbols I noticed in my WPR report were somewhat different, mostly variations of "CcUnpinRepinnedBcb".

I ended up finding out that the "docker context ls" command is called from both the mentioned VSCode extension, and Docker Desktop itself - I'm assuming for polling the container status, cpu usage, etc. Removing the extension only fixed part of the problem though, since most of the polling is still being done by Docker Desktop.

After reading your last comment I got curious and ended up finding your related post on the Framework forums. After trying the test described there (not on a clean install) I now suspect that this is indeed unrelated to docker, just a side effect due to docker desktop calling that process in loop.

I'm not even using the same laptop as you though (Asus X13 2022, AMD Ryzen 9 model), so not sure where to go from here.

totoguy commented 6 months ago

@lukas-lang This seems promising, will test out the driver downgrade in the next day or two. https://community.amd.com/t5/drivers-software/memory-leak-on-zen4/td-p/662281

lukas-lang commented 6 months ago

@totoguy Wow, nice find! Downgrading to version 23.10.2 of the AMD drivers does indeed seem to fix the issue

joelsodias commented 1 month ago

Hello there...

That's the same situation here, and I'm using an Intel(R) Core(TM) i5-1035G1 CPU

Does anybody have a clue how to avoid this situation?

image

docker_desktop