Connecting to long running Dev Container takes extremely long time
This is connecting to a persistent docker container I manually started, and then attaching to the container via the remote explorer. I am working inside this container for a lengthy period of time, which is started with CMD like:
"Cmd": [
"/bin/bash",
"-c",
"tail -f /dev/null"
],
Over time, the number of defunct processes grows within the container. When I attempt to reconnect to the container, there is a significant bottleneck in the following steps:
[23089 ms] Start: Run in container: for pid in `cd /proc && ls -d [0-9]*`; do { echo $pid ; readlink /proc/$pid/cwd || echo ; readlink /proc/$pid/ns/mnt || echo ; cat /proc/$pid/stat | tr "
[23864 ms]
[23864 ms]
[26440 ms] userEnvProbe PATHs:
...
...
[279891 ms] Start: Run in container: for pid in `cd /proc && ls -d [0-9]*`; do { echo $pid ; readlink /proc/$pid/cwd || echo ; readlink /proc/$pid/ns/mnt || echo ; cat /proc/$pid/stat | tr "
...
...
[532731 ms] Start: Run in container: mkdir -p '/tmp/devcontainers-xxxxxx' && cat > '/tmp/devcontainers-devcontainers-xxxxxx/env-loginInteractiveShell.json' << 'envJSON'
...
Only workaround I have found is to restart the container, which cleans up all of the zombie processes. Then connecting to the container is fast again.
Thanks for opening. @chrmarti I wonder if you have thoughts here?
Reading process information from the proc filesystem will slow down with a large number of process. We could look into optimizing that.
Are the zombie processes caused by a bug in VS Code or by something else?
No, zombie processes are just a side effect of the docker init process not automatically cleaning up processes when they terminate.
For example, when manually starting container, one might use a simple sleep command or:
"Cmd": [
"/bin/bash",
"-c",
"tail -f /dev/null"
],
Then all processes started within the container would be child processes of the main process, and don't get cleaned up until the docker container is stopped.
One solution I think is probably just pass --init flag to docker run so that zombie processes can get cleaned up.