microsoft / vscode-remote-release

Visual Studio Code Remote Development: Open any folder in WSL, in a Docker container, or on a remote machine using SSH and take advantage of VS Code's full feature set.
https://aka.ms/vscode-remote
Other
3.62k stars 279 forks source link

Dev container dies when launched from Mac Shortcuts app #9939

Open navels opened 3 months ago

navels commented 3 months ago

This is an extremely odd bug and seems specific to launching a dev container via a Mac shortcut. (These aren't shortcuts like desktop shortcuts in Windows but rather scripts created in the Shortcuts app.). I like to have a list of workspaces to open as shortcuts so I can just click the Shortcuts icon on the menu bar (top right on the mac) and select a workspace to open. The problem is that one of those workspaces is a dev container and if I have that open, its dev container dies sixty-ish seconds after opening another workspace via a shortcut.

Narrowed this down to a barebones repro but still mystified as to what is going on.

Steps to Reproduce:

  1. Create a dev container test setup via
    
    mkdir -p /tmp/test/.devcontainer

cat < /tmp/test/docker-compose.yml services: test: image: debian:latest command: tail -f /dev/null EOF

cat < /tmp/test/.devcontainer/devcontainer.json { "name": "test", "service": "test", "dockerComposeFile": "../docker-compose.yml", } EOF


2. Open the Mac shortcuts app and create a new shortcut via File > New Shortcut.  Add an action "Run Shell Script" with this as its contents:

/usr/local/bin/code --folder-uri "vscode-remote://dev-container+$(xxd -p -c 1024 <<<'{"hostPath":"/tmp/test"}')"

Call this shortcut "test" and save it.

4. Create another shell script shortcut called "noop" that has an empty body.  (Note: there is nothing interesting about this being a noop.  I discovered this bug using a second shortcut that was another vscode invocation, just so happens it repros with a noop shortcut as well.)

5. Run the test shortcut, and wait for it to launch vscode and start the dev container.  Next step can be run now or later, doesn't seem to matter when.

6. Run the noop shortcut.  After about 60 seconds the dev container will die and vscode will complain "Cannot reconnect".

Logs from starting up the dev container:

[15 ms] Dev Containers 0.362.0 in VS Code 1.89.1 (dc96b837cf6bb4af9cd736aa3af08cf8279f7685). [15 ms] Start: Resolving Remote [23 ms] Setting up container for folder or workspace: /tmp/test [24 ms] Start: Check Docker is running [24 ms] Start: Run: docker version [76 ms] Client: Cloud integration: v1.0.35+desktop.13 Version: 26.1.1 API version: 1.45 Go version: go1.21.9 Git commit: 4cf5afa Built: Tue Apr 30 11:44:56 2024 OS/Arch: darwin/arm64 Context: default

Server: Docker Desktop 4.30.0 (149282) Engine: Version: 26.1.1 API version: 1.45 (minimum version 1.24) Go version: go1.21.9 Git commit: ac2de55 Built: Tue Apr 30 11:48:04 2024 OS/Arch: linux/arm64 Experimental: false containerd: Version: 1.6.31 GitCommit: e377cd56a71523140ca6ae87e30244719194a521 runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0 [79 ms] Start: Run: docker volume ls -q [141 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=/tmp/test --filter label=vsch.quality=stable [203 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/tmp/test --filter label=devcontainer.config_file=/tmp/test/.devcontainer/devcontainer.json [252 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/tmp/test [301 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/tmp/test [367 ms] Running Dev Containers CLI: read-configuration --workspace-folder /tmp/test --id-label devcontainer.local_folder=/tmp/test --id-label devcontainer.config_file=/tmp/test/.devcontainer/devcontainer.json --log-level debug --log-format json --config /tmp/test/.devcontainer/devcontainer.json --mount-workspace-git-root [386 ms] ProxyResolver#loadSystemCertificates count [387 ms] ProxyResolver#loadSystemCertificates count filtered [388 ms] Start: Run: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users//.vscode/extensions/ms-vscode-remote.remote-containers-0.362.0/dist/spec-node/devContainersSpecCLI.js read-configuration --workspace-folder /tmp/test --id-label devcontainer.local_folder=/tmp/test --id-label devcontainer.config_file=/tmp/test/.devcontainer/devcontainer.json --log-level debug --log-format json --config /tmp/test/.devcontainer/devcontainer.json --mount-workspace-git-root [546 ms] @devcontainers/cli 0.59.1. Node.js v18.18.2. darwin 23.5.0 arm64. [546 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/tmp/test --filter label=devcontainer.config_file=/tmp/test/.devcontainer/devcontainer.json [604 ms] Running Dev Containers CLI: up --user-data-folder /Users//Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-19a18609-c692-4ef0-8de1-329defc1972a1717100316962 --workspace-folder /tmp/test --workspace-mount-consistency cached --id-label devcontainer.local_folder=/tmp/test --id-label devcontainer.config_file=/tmp/test/.devcontainer/devcontainer.json --log-level debug --log-format json --config /tmp/test/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root [604 ms] Start: Run: /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) /Users//.vscode/extensions/ms-vscode-remote.remote-containers-0.362.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /Users//Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-19a18609-c692-4ef0-8de1-329defc1972a1717100316962 --workspace-folder /tmp/test --workspace-mount-consistency cached --id-label devcontainer.local_folder=/tmp/test --id-label devcontainer.config_file=/tmp/test/.devcontainer/devcontainer.json --log-level debug --log-format json --config /tmp/test/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root [754 ms] @devcontainers/cli 0.59.1. Node.js v18.18.2. darwin 23.5.0 arm64. [754 ms] Start: Run: docker buildx version [825 ms] github.com/docker/buildx v0.14.0-desktop.1 7b0470cffd54ccbf42976d2f75febc4532c85073 [825 ms] [825 ms] Start: Run: docker -v [859 ms] Start: Resolving Remote [861 ms] Loading 18 extra certificates from /var/folders/zw/4y5l9c393ybfg4fw6xmxx2x80000gp/T/com.apple.shortcuts.mac-helper/vsch/certificates-4c347e5357bb3fb44d29f9eb3742ca589f5811367c5ec8237de5611cde30bd55.pem. [922 ms] Start: Run: docker-compose version --short [991 ms] Docker Compose version: 2.27.0-desktop.2 [991 ms] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=test --filter label=com.docker.compose.service=test [1054 ms] Start: Run: docker-compose -f /tmp/test/docker-compose.yml --profile * config [1154 ms] name: test services: test: command:

[8969 ms] Start: Run in container: test -d '/root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685' [8970 ms] [8970 ms] [8970 ms] Exit code 1 [8970 ms] Start: Run in container: test -d '/vscode/vscode-server/bin/linux-arm64/dc96b837cf6bb4af9cd736aa3af08cf8279f7685' [8971 ms] [8971 ms] [8971 ms] Start: Run in container: mkdir -p '/root/.vscode-server/bin' && ln -snf '/vscode/vscode-server/bin/linux-arm64/dc96b837cf6bb4af9cd736aa3af08cf8279f7685' '/root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685' [8972 ms] [8972 ms] [8973 ms] Start: Run in container: touch '/vscode/vscode-server/bin/linux-arm64/dc96b837cf6bb4af9cd736aa3af08cf8279f7685' [8973 ms] [8973 ms] [8973 ms] Start: Run in container: test -x '/root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/bin/helpers/check-requirements.sh' [8974 ms] [8974 ms] [8974 ms] Start: Run in container: '/root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/bin/helpers/check-requirements.sh' [8990 ms] [8990 ms] [8991 ms] Start: Launching Dev Containers helper. [8991 ms] ssh-agent: SSH_AUTH_SOCK in container (/tmp/vscode-ssh-auth-e2072778-d3f5-46ab-9338-cf2f79f8cd38.sock) forwarded to local host (/private/tmp/com.apple.launchd.OHDq3iuvKv/Listeners). [8991 ms] X11 forwarding: DISPLAY not set on local host. [8991 ms] Start: Run in container: gpgconf --list-dir agent-socket [8992 ms] [8992 ms] /bin/sh: 14: gpgconf: not found [8992 ms] Exit code 127 [8992 ms] gpg-agent: No agent-socket found in container. [8992 ms] Start: Run in container: command -v docker >/dev/null 2>&1 [8993 ms] [8993 ms] [8993 ms] Exit code 127 [8993 ms] Start: Run in container: /bin/sh [8995 ms] userEnvProbe: loginInteractiveShell (default) [8995 ms] Start: Run in container: test -f '/tmp/devcontainers-19a18609-c692-4ef0-8de1-329defc1972a1717100316962/env-loginInteractiveShell.json' [8995 ms] Start: Run in container: echo ~ [8996 ms] [8996 ms] [8996 ms] Exit code 1 [8996 ms] Start: Run in container: command -v git >/dev/null 2>&1 && git config --system --replace-all credential.helper '!f() { /root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/node /tmp/vscode-remote-containers-e2072778-d3f5-46ab-9338-cf2f79f8cd38.js git-credential-helper $; }; f' || true [8996 ms] userEnvProbe: not found in cache [8996 ms] userEnvProbe shell: /bin/bash [8997 ms] [8997 ms] [8997 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 " [9010 ms] Start: Run in container: cat '/root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/product.json' [9012 ms] Start: Run in container: cat '/root/.vscode-server/data/Machine/.connection-token-dc96b837cf6bb4af9cd736aa3af08cf8279f7685' 2>/dev/null || (umask 377 && echo 'da067fa5-cb66-4808-b766-9009d07e334f' >'/root/.vscode-server/data/Machine/.connection-token-dc96b837cf6bb4af9cd736aa3af08cf8279f7685-217e8ee1-e715-47f2-a568-09423569b9da' && mv -n '/root/.vscode-server/data/Machine/.connection-token-dc96b837cf6bb4af9cd736aa3af08cf8279f7685-217e8ee1-e715-47f2-a568-09423569b9da' '/root/.vscode-server/data/Machine/.connection-token-dc96b837cf6bb4af9cd736aa3af08cf8279f7685' && rm -f '/root/.vscode-server/data/Machine/.connection-token-dc96b837cf6bb4af9cd736aa3af08cf8279f7685-217e8ee1-e715-47f2-a568-09423569b9da' && cat '/root/.vscode-server/data/Machine/.connection-token-dc96b837cf6bb4af9cd736aa3af08cf8279f7685') [9014 ms] da067fa5-cb66-4808-b766-9009d07e334f [9015 ms] [9015 ms] Start: Starting VS Code Server [9015 ms] Start: Preparing Extensions [9015 ms] Start: Run in container: test ! -f '/root/.vscode-server/data/Machine/.installExtensionsMarker' && set -o noclobber && mkdir -p '/root/.vscode-server/data/Machine' && { > '/root/.vscode-server/data/Machine/.installExtensionsMarker' ; } 2> /dev/null [9017 ms] [9017 ms] [9018 ms] Extensions cache, install extensions: None [9018 ms] Start: Run in container: test -d /root/.vscode-server/extensionsCache && ls /root/.vscode-server/extensionsCache || true [9019 ms] [9019 ms] [9019 ms] Start: Run in container: test -d /vscode/vscode-server/extensionsCache && ls /vscode/vscode-server/extensionsCache || true [9020 ms] github.copilot-1.196.0 github.copilot-1.197.0 github.copilot-chat-0.15.2 [9020 ms] [9021 ms] Extensions cache, link in container: None [9021 ms] Optimizing extensions for quality: stable [9021 ms] Start: Run in container: /root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/bin/code-server --log debug --force-disable-user-env --server-data-dir /root/.vscode-server --use-host-proxy --telemetry-level all --accept-server-license-terms --host 127.0.0.1 --port 0 --connection-token-file /root/.vscode-server/data/Machine/.connection-token-dc96b837cf6bb4af9cd736aa3af08cf8279f7685 --extensions-download-dir /root/.vscode-server/extensionsCache --start-server --disable-websocket-compression --skip-requirements-check [9075 ms] /root [9075 ms] [9075 ms] Start: Run in container: cat <<'EOF-/tmp/vscode-remote-containers-e2072778-d3f5-46ab-9338-cf2f79f8cd38.js' >/tmp/vscode-remote-containers-e2072778-d3f5-46ab-9338-cf2f79f8cd38.js [9076 ms] [9076 ms] [9076 ms] Start: Run in container: cat <<'EOF-/tmp/vscode-remote-containers-server-e2072778-d3f5-46ab-9338-cf2f79f8cd38.js' >/tmp/vscode-remote-containers-server-e2072778-d3f5-46ab-9338-cf2f79f8cd38.js_1717100326417 [9079 ms] [9079 ms] [9100 ms] *

[9103 ms] Start: Run in container: echo 34183 >'/root/.vscode-server/data/Machine/.devport-dc96b837cf6bb4af9cd736aa3af08cf8279f7685' [9104 ms] [9104 ms] [9104 ms] Port forwarding for container port 34183 starts listening on local port. [9104 ms] Port forwarding local port 34183 to container port 34183 [9105 ms] Start: Run in container: # Test for /root/.gitconfig and git [9106 ms] git not found [9106 ms] [9106 ms] Exit code 1 [9106 ms] Start: Run in container: # Cleaning up git config [9108 ms] [9108 ms] /bin/sh: 36: git: not found /bin/sh: 36: git: not found /bin/sh: 36: git: not found /bin/sh: 41: git: not found [9108 ms] Start: Run in container: command -v git >/dev/null 2>&1 && git config --global --replace-all credential.helper '!f() { /root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/node /tmp/vscode-remote-containers-e2072778-d3f5-46ab-9338-cf2f79f8cd38.js git-credential-helper $*; }; f' || true [9109 ms] [9109 ms] [9118 ms] userEnvProbe PATHs: Probe: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' Container: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' [9119 ms] Start: Run in container: mkdir -p '/tmp/devcontainers-19a18609-c692-4ef0-8de1-329defc1972a1717100316962' && cat > '/tmp/devcontainers-19a18609-c692-4ef0-8de1-329defc1972a1717100316962/env-loginInteractiveShell.json' << 'envJSON' [9120 ms] [9120 ms] [9123 ms] Initializing configuration support... [9123 ms] Internal initialization of dev container support package... [9125 ms] Port forwarding connection from 54150 > 34183 > 34183 in the container. [9126 ms] Start: Run in container: /root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/node -e [9171 ms] Ignoring option 'skip-requirements-check': not supported for server. [9178 ms] [20:18:46]

[9190 ms] [20:18:46] Extension host agent started. [9208 ms] Port forwarding 54150 > 34183 > 34183 stderr: Connection established [9217 ms] [20:18:46] No uninstalled extensions found. [9218 ms] [20:18:46] Started initializing default profile extensions in extensions installation folder. file:///root/.vscode-server/extensions [9223 ms] [20:18:46] ComputeTargetPlatform: linux-arm64 [9225 ms] [20:18:46] [127.0.0.1][1c710dbc][ManagementConnection] New connection established. [9227 ms] Port forwarding connection from 54154 > 34183 > 34183 in the container. [9227 ms] Start: Run in container: /root/.vscode-server/bin/dc96b837cf6bb4af9cd736aa3af08cf8279f7685/node -e [9231 ms] [20:18:46] Completed initializing default profile extensions in extensions installation folder. file:///root/.vscode-server/extensions [9234 ms] [20:18:46] Log level changed to info [9324 ms] Port forwarding 54154 > 34183 > 34183 stderr: Connection established [9439 ms] [20:18:46] [127.0.0.1][ef032c30][ExtensionHostConnection] New connection established. [9444 ms] [20:18:46] [127.0.0.1][ef032c30][ExtensionHostConnection] <296> Launched Extension Host Process. [10075 ms] Start: Run in container: cat /proc/332/environ


Logs when the container dies (these and the above are the entirety of the dev container logs):

[259927 ms] Exit code 137 [259927 ms] Keep-alive process ended. [259946 ms] Port forwarding 54150 > 34183 > 34183 terminated with code 137 and signal null. [259947 ms] Container server terminated (code: 137, signal: null). [259948 ms] Port forwarding 54154 > 34183 > 34183 terminated with code 137 and signal null. [259948 ms] Port forwarding 54150 > 34183 > 34183: Local close [259949 ms] Port forwarding 54154 > 34183 > 34183: Local close [259949 ms] Start: Reconnection attempt 1 [259949 ms] Start: Run: docker inspect --type container 24e48e9e97957b169c953a3c98355f14ccdf1816094cf9671f82dbb6620afe8d [319090 ms] Stdin closed!

navels commented 3 months ago

Interestingly this isn't a problem with attaching to an existing container, i.e., I can work around this problem by using this shortcut:

docker compose -f /tmp/test/docker-compose.yml up -d
/usr/local/bin/code --folder-uri "vscode-remote://attached-container+$(xxd -p -c 1024 <<<'{"containerName":"/test-test-1"}')"