cli icon indicating copy to clipboard operation
cli copied to clipboard

Connecting to long running Dev Container takes extremely long time

Open ryxli opened this issue 1 year ago • 4 comments

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.

ryxli avatar Jan 16 '25 21:01 ryxli

Thanks for opening. @chrmarti I wonder if you have thoughts here?

bamurtaugh avatar Jan 30 '25 22:01 bamurtaugh

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?

chrmarti avatar Feb 03 '25 22:02 chrmarti

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.

ryxli avatar Feb 03 '25 22:02 ryxli

One solution I think is probably just pass --init flag to docker run so that zombie processes can get cleaned up.

ryxli avatar Feb 07 '25 22:02 ryxli