Dev Containers: .devport file is shared between containers that bind-mount the same ~/.vscode-server, causing "already running" server to be forwarded to the wrong port (WebSocket close 1006)
- VSCode Version: 1.139.1 (04c0d99f4fb0d8afe6ce4f0c58e31e183ac3e4b1)
- Local OS Version: macOS 26 (Darwin 25.6.0, arm64)
- Remote OS Version: Ubuntu (kernel 5.15.0-190-generic), Docker Engine 29.8.0. Containers: Debian 13 and CentOS Stream 9.
- Remote Extension/Connection Type: Dev Containers 0.469.0 ("Attach to Running Container") over Remote - SSH 0.128.0
- Logs: excerpts inline below, full Dev Containers logs for both windows attached.
Summary
When two containers on the same Docker host bind-mount the same ~/.vscode-server directory (very common for "attach to running container" dev setups where the user's home is mounted into every container), the Dev Containers extension stores each container's VS Code Server port in the same file: ~/.vscode-server/data/Machine/.devport-<commit>
Whichever container's server started last overwrites the file. When a window attached to the other container later reloads, the extension:
- scans
/procinside the container, finds its server process, and logsExtension host agent is already running.; - reads the port from the shared
.devport-<commit>file, which now holds the other container's port; - forwards to that port, where nothing listens in this container.
Every forwarded connection fails with connect ECONNREFUSED 127.0.0.1:<port> inside the container, the local forwarder closes the socket, and the window shows:
Failed to connect to the remote extension host server (Error: WebSocket close with status code 1006)
Reloading the window never helps because the detection is stable. The only recovery is to kill the server in the container (e.g. docker restart), which makes the extension start a new server, which then overwrites .devport again and sets up the other container to fail the next time it fully re-resolves. The two windows keep taking turns breaking each other.
Because the server is launched with a random port (--port 0), the port is not in the process command line, so the .devport file is the only record the extension has.
Steps to Reproduce
- On a Docker host, run two containers that both bind-mount the same
~/.vscode-server(e.g. container A mounts/home/user:/home/user, container B mounts/home/user/.vscode-server:/home/user/.vscode-server). - From VS Code, "Attach to Running Container" to container A. A server starts on port P_A; the extension writes P_A to
~/.vscode-server/data/Machine/.devport-<commit>. - In a second window, attach to container B. A server starts on port P_B and overwrites the same file with P_B.
- Reload the window attached to container A (Developer: Reload Window).
- The Dev Containers log shows
Extension host agent is already running., thenPort forwarding local port X to container port P_B, then repeatedconnect ECONNREFUSED 127.0.0.1:P_B. The window fails withWebSocket close with status code 1006and stays broken across reloads.
The same happens over plain SSH and with a local Docker host; the Remote - SSH layer is not involved.
Evidence from the logs
Container A (foo), server start:
[2026-09-26T14:46:35.253Z] Start: Run in container: .../bin/code-server ... --host 127.0.0.1 --port 0 ...
Extension host agent listening on 34551
[2026-09-26T14:46:35.759Z] Start: Run in container: echo 34551 >'/home/benoit/.vscode-server/data/Machine/.devport-04c0d99f4fb0d8afe6ce4f0c58e31e183ac3e4b1'
Container B (bar), server start the next day, same file:
[2026-09-27T07:07:49.309Z] Start: Run in container: .../bin/code-server ... --host 127.0.0.1 --port 0 ...
Extension host agent listening on 39283
[2026-09-27T07:07:49.993Z] Start: Run in container: echo 39283 >'/home/benoit/.vscode-server/data/Machine/.devport-04c0d99f4fb0d8afe6ce4f0c58e31e183ac3e4b1'
Container A window reloaded:
[2026-09-28T11:28:55.350Z] Setting up container: /foo
[2026-09-28T11:29:45.842Z] Extension host agent is already running.
[2026-09-28T11:29:46.247Z] Port forwarding local port 61934 to container port 39283
[2026-09-28T11:29:47.643Z] Port forwarding connection from 61935 > 61934 > 39283 in the container.
[2026-09-28T11:29:48.067Z] Port forwarding 61935 > 61934 > 39283 stderr: Error: connect ECONNREFUSED 127.0.0.1:39283
[2026-09-28T11:29:48.079Z] Port forwarding 61935 > 61934 > 39283 terminated with code 1 and signal null.
[2026-09-28T11:29:48.080Z] Port forwarding 61935 > 61934 > 39283: Local close
(repeats for every reconnection attempt)
Window log at the same time:
[remote-connection][Management ][a520a…][initial][WebSocket(127.0.0.1:61934)] socketFactory.connect() failed or timed out. Error:
CodeExpectedError: WebSocket close with status code 1006
Verified on the host at the time of failure: container A's server was listening on 127.0.0.1:34551, container B's on 127.0.0.1:39283, and the shared .devport-04c0d99f… contained 39283.
$ docker inspect foo --format '{{range .Mounts}}{{.Source}} -> {{.Destination}}{{"\n"}}{{end}}'
/home/benoit -> /home/benoit
/var/run/docker.sock -> /var/run/docker.sock
$ docker inspect bar --format '...'
...
/home/benoit/.vscode-server -> /home/benoit/.vscode-server
...
The same sequence appears twice more in my logs over the previous two days, each time "fixed" by docker restart of the affected container.
Expected Behavior
Reloading a window attached to a container whose VS Code Server is still running should reconnect to that server, regardless of what other containers sharing the same ~/.vscode-server have done.
Possible fixes, any of which would work:
- Verify that the port read from
.devport-<commit>is actually owned by the server process that was found (e.g. match the LISTEN socket inode in/proc/<pid>/fdagainst/proc/net/tcp), and fall back to the existing "Agent port not found. Terminating old extension host agent." path when it is not. - Record the port somewhere container-local instead of (or in addition to) the shared data folder, e.g. next to the
/tmp/vscode-remote-containers-<id>.jshelper files the extension already writes into the container, or keyed by the container id. - Have the server write its port to a file whose name includes something container-specific, or pass a fixed
--portderived per container so it is visible in the process command line.
Actual Behavior
The extension trusts the shared .devport-<commit> file, forwards to another container's port, gets ECONNREFUSED on every attempt, and the window fails with WebSocket close with status code 1006 until the server in the container is killed.
Does this issue occur when you try this locally?: Yes (a local Docker host with two containers sharing ~/.vscode-server behaves the same; the SSH hop is irrelevant)
Does this issue occur when you try this locally and all extensions are disabled?: N/A (the bug is in the Dev Containers extension itself)
Anything else?
- The
.connection-token-<commit>file is shared the same way. That happens to be harmless today because the second server reuses the existing token, but it is the same class of problem. - Possibly the same root cause as #9311 ("Failed to open old devcontainer after open a new one", ECONNREFUSED on the extension host port).
- Workaround for anyone hitting this: from the host, find the real listening port with
docker exec <container> cat /proc/net/tcp(state0A, address0100007F), write it into~/.vscode-server/data/Machine/.devport-<commit>, and reload the window. Or give each container its own~/.vscode-server/data/Machinemount.
Pushed a workaround at tsuna/quicssh@8f978d6bc465809e951db9f1d931da7e8a70d045, but it's kinda crappy... it's the same fundamental problem as #11463: the extension is closed source so this cannot be fixed properly. I wish Microsoft took community contributions on these extensions. It's not clear why they're kept closed source.
This behavior has been haunting me for a long time. I have multiple projects on a single server all using devcontainer and killing them all on each reconnect is painful.
Mounting in a dummy directory in the project to map to the $HOME/.vscode-server/data/Machine directory in the devcontainer docker-compose.yml worked for me to make this data unique per project.
volumes:
- .:/code:cached
- $HOME:$HOME
- ./.devcontainer:$HOME/.vscode-server/data/Machine
I reproduced the same issue with three containers sharing a Docker named volume, and verified a workaround that preserves the shared VS Code Server installation.
Environment
- VS Code 1.147.0, commit
8a14f0cc1b08d531eb83255ea3764ae22aa932b5 - Windows client → Remote - SSH → Linux Docker host
- Three containers, each managed by a separate Docker Compose project
- All three mounted the same external volume at
/root/.vscode-server
The shared installation is intentional: it avoids downloading and storing the same server binaries separately for each container.
Observed behavior
The containers wrote to the same data/Machine/.devport-<commit> file. Starting the server in another container overwrote the cached port, even though the containers had separate server processes and network namespaces.
A subsequent connection could therefore use another container's cached port, resulting in ECONNREFUSED and WebSocket close code 1006.
Verified workaround
We kept the original shared volume and added a private volume for the entire data directory.
Relevant Compose fragment:
services:
dev:
volumes:
- vscode-server:/root/.vscode-server
- vscode-server-data:/root/.vscode-server/data
volumes:
vscode-server:
external: true
vscode-server-data:
Each instance uses a separate Compose project, so vscode-server-data resolves to a different volume for each instance. This fragment would not isolate multiple services or replicas within the same project.
After applying this change:
- All three fresh VS Code client connections succeeded and could read their remote workspaces.
- Each cached port reached the expected server version inside its own container.
- Connection tokens and state directories were independent.
- Writing to the same relative path in each private state directory did not affect the others.
- The existing shared server installation and extensions remained in place.
Requested improvement
Could Dev Containers support this separation automatically: share installed/downloaded server files while keeping runtime connection metadata container-local?
In particular:
- Scope cached ports and related connection metadata to the target container instance.
- Before reusing a cached endpoint, verify that it belongs to the expected server process inside that container.
- Add regression coverage for connecting to A, then B, reconnecting/reloading both, and restarting or recreating one without breaking the other.
This would preserve the download/storage benefit of a shared installation without requiring users to discover and configure private runtime-state mounts manually.
Mọi người có thể giúp tôi đc không , tôi bị dev cài mã độc vào máy tính , khiến máy tính và điẹn thoại của cả gia đình đều lộ dữ liệu , các vấn đề về sử dụng code bị đẩy lên github hoàn toàn ko phải do tôi , tôi cần giúp đỡ
Linh
Vào CN, 22 thg 11, 2026 lúc 08:44 z-xhh @.***> đã viết:
z-xhh left a comment (microsoft/vscode-remote-release#11883) https://github.com/microsoft/vscode-remote-release/issues/11883#issuecomment-7072403325
I reproduced the same issue with three containers sharing a Docker named volume, and verified a workaround that preserves the s shared VS Code Server installation. Environment
- VS Code 1.147.0, commit 8a14f0cc1b08d531eb83255ea3764ae22aa932b5
- Windows client → Remote - SSH → Linux Docker host
- Three containers, each managed by a separate Docker Compose project
- All three mounted the same external volume at /root/.vscode-server
The shared installation is intentional: it avoids downloading and storing the same server binaries separately for each container. Observed behavior
The containers wrote to the same data/Machine/.devport-
file. Starting the server in another container overwrote the cached port, even though the containers had separate server processes and network namespaces. A subsequent connection could therefore use another container's cached port, resulting in ECONNREFUSED and WebSocket close code 1006. Verified workaround
We kept the original shared volume and added a private volume for the entire data directory.
Relevant Compose fragment:
services: dev: volumes: - vscode-server:/root/.vscode-server - vscode-server-data:/root/.vscode-server/data volumes: vscode-server: external: true vscode-server-data:
Each instance uses a separate Compose project, so vscode-server-data resolves to a different volume for each instance. This fragment would not isolate multiple services or replicas within the same project.
After applying this change:
- All three fresh VS Code client connections succeeded and could read their remote workspaces.
- Each cached port reached the expected server version inside its own container.
- Connection tokens and state directories were independent.
- Writing to the same relative path in each private state directory did not affect the others.
- The existing shared server installation and extensions remained in place.
Requested improvement
Could Dev Containers support this separation automatically: share installed/downloaded server files while keeping runtime connection metadata container-local?
In particular:
- Scope cached ports and related connection metadata to the target container instance.
- Before reusing a cached endpoint, verify that it belongs to the expected server process inside that container.
- Add regression coverage for connecting to A, then B, reconnecting/reloading both, and restarting or recreating one without breaking the other.
This would preserve the download/storage benefit of a shared installation without requiring users to discover and configure private runtime-state mounts manually.
— Reply to this email directly, view it on GitHub https://github.com/microsoft/vscode-remote-release/issues/11883?email_source=notifications&email_token=CSQXQGAY2FHSRD34BQA7WY352JAI7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMBXGI2DAMZTGI22M4TFMFZW63VGNVQW45LBNSSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-7072403325, or unsubscribe https://github.com/notifications/unsubscribe-auth/CSQXQGELGC6NDLUAM52ZNW352JAI7AVCNFSNUABFKJSXA33TNF2G64TZHMYTONZYGM4TCOJUHNEXG43VMU5TKNRRGUZDAOJSGIYKC5QC . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/CSQXQGHNBCP6PAEIY6WBAD352JAI7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMBXGI2DAMZTGI22M4TFMFZW63VGNVQW45LBNSSWK5TFNZ2KUZTPN52GK4S7NFXXG and Android https://github.com/notifications/mobile/android/CSQXQGHPVJMAZFUG5QIZ2ML52JAI7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMBXGI2DAMZTGI22M4TFMFZW63VGNVQW45LBNSSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA. Download it today! You are receiving this because you are subscribed to this thread.Message ID: @.***>