Skip to content

VS Code keeps disconnecting if the client device sleeps #413

@matifali

Description

@matifali
Member

Hi Team! When using Cursor/VSCode desktop, whenever we close and reopen laptop even for a few seconds, we see a popup Cannot reconnect. Please reload the window. I was wondering if this is expected behavior and if you might be aware of some settings that would make VSCode reconnect more smoothly? I tried changing connect timeout and max reconnection attempts so far but didn't see a difference.

VSCode connection often disconnects even for a slight network issue or if the device sleeps. I am unsure if this is caused by how VSCode handles remote connections as coder ssh <workspace> survives device sleep.

Activity

added and removed
help wantedExtra attention is needed
on Feb 3, 2025
f0ssel

f0ssel commented on Feb 10, 2025

@f0ssel
Contributor

It is possible that #420 may have solved this issue. @bcpeinhardt said he's going to try to see if he can repro and confirm if this change fixes things.

bcpeinhardt

bcpeinhardt commented on Feb 13, 2025

@bcpeinhardt
Collaborator

@bpmct curious why this is marked as blocked?

bcpeinhardt

bcpeinhardt commented on Feb 13, 2025

@bcpeinhardt
Collaborator

Leaving as todo in Bugs Board because it doesn't seem to have a Blocked status available.

bpmct

bpmct commented on Feb 14, 2025

@bpmct
Member

@matifali told me we are are unable to reproduce and waiting on a user. If we are able to repro, this feel pretty important so don't mean to arbitrarily "block" anything

assigned and unassigned on Feb 24, 2025

8 remaining items

csibe17

csibe17 commented on May 12, 2025

@csibe17

I can still reproduce the issue.

Image

If I hit cancel I can find these logs in Remote - SSH output:

[17:53:31.250] SSH Resolver called for "ssh-remote+coder-vscode.yourcoderdomain.com--gabor--gabor2", attempt 6, (Reconnection)
[17:53:31.252] SSH Resolver called for host: coder-vscode.yourcoderdomain.com--gabor--gabor2
[17:53:31.252] Setting up SSH remote "coder-vscode.yourcoderdomain.com--gabor--gabor2"
[17:53:31.253] Acquiring local install lock: /var/folders/tl/505vltyj0tn8bpn6dyzywjxc0000gn/T/vscode-remote-ssh-aa6aec7a-install.lock
[17:53:31.255] Looking for existing server data file at /Users/gaborcseh/Library/Application Support/Cursor/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-aa6aec7a-7801a556824585b7f2721900066bc87c4a09b740-0.113.1-tr/data.json
[17:53:31.255] Using commit id "7801a556824585b7f2721900066bc87c4a09b740" and quality "stable" for server
[17:53:31.258] Install and start server if needed
[17:53:31.261] askpass server listening on /var/folders/tl/505vltyj0tn8bpn6dyzywjxc0000gn/T/vscode-ssh-askpass-ec152e3e5721b0960dc108bf329c95ae2d54615d.sock
[17:53:31.261] Spawning local server with {"serverId":6,"ipcHandlePath":"/var/folders/tl/505vltyj0tn8bpn6dyzywjxc0000gn/T/vscode-ssh-askpass-f6483eedef8aff168507b29f9d1f65b9851ed83a.sock","sshCommand":"ssh","sshArgs":["-v","-T","-D","61210","-o","ConnectTimeout=1800","coder-vscode.yourcoderdomain.com--gabor--gabor2","bash"],"serverDataFolderName":".cursor-server","dataFilePath":"/Users/gaborcseh/Library/Application Support/Cursor/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-aa6aec7a-7801a556824585b7f2721900066bc87c4a09b740-0.113.1-tr/data.json"}
[17:53:31.262] Local server env: {"SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.PG3V74XFGC/Listeners","SHELL":"/bin/zsh","DISPLAY":"1","ELECTRON_RUN_AS_NODE":"1","SSH_ASKPASS":"/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/local-server/askpass.sh","VSCODE_SSH_ASKPASS_NODE":"/Applications/Cursor.app/Contents/Frameworks/Cursor Helper (Plugin).app/Contents/MacOS/Cursor Helper (Plugin)","VSCODE_SSH_ASKPASS_EXTRA_ARGS":"","VSCODE_SSH_ASKPASS_MAIN":"/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/askpass-main.js","VSCODE_SSH_ASKPASS_HANDLE":"/var/folders/tl/505vltyj0tn8bpn6dyzywjxc0000gn/T/vscode-ssh-askpass-ec152e3e5721b0960dc108bf329c95ae2d54615d.sock"}
[17:53:31.262] Spawned 80446
[17:53:31.340] > local-server-6> Running ssh connection command: ssh -v -T -D 61210 -o ConnectTimeout=1800 coder-vscode.yourcoderdomain.com--gabor--gabor2 bash
[17:53:31.341] > local-server-6> Spawned ssh, pid=80449
[17:53:31.344] stderr> OpenSSH_9.6p1, LibreSSL 3.3.6
[17:53:31.359] stderr> Encountered an error running "coder ssh", see "coder ssh --help" for more information
[17:53:31.359] stderr> error: Get "https://yourcoderdomain.com/api/v2/users/gabor/workspace/gabor2?include_deleted=false": dial tcp: lookup yourcoderdomain.com: no such host
[17:53:31.359] stderr> kex_exchange_identification: Connection closed by remote host
[17:53:31.359] stderr> Connection closed by UNKNOWN port 65535
[17:53:31.360] > local-server-6> ssh child died, shutting down
[17:53:31.363] Local server exit: 0
[17:53:31.363] Received install output: local-server-6> Running ssh connection command: ssh -v -T -D 61210 -o ConnectTimeout=1800 coder-vscode.yourcoderdomain.com--gabor--gabor2 bash
local-server-6> Spawned ssh, pid=80449
OpenSSH_9.6p1, LibreSSL 3.3.6
Encountered an error running "coder ssh", see "coder ssh --help" for more information
error: Get "https://yourcoderdomain.com/api/v2/users/gabor/workspace/gabor2?include_deleted=false": dial tcp: lookup yourcoderdomain.com: no such host
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535
local-server-6> ssh child died, shutting down

[17:53:31.363] Failed to parse remote port from server output
[17:53:31.369] Resolver error: Error: 
	at m.Create (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:501230)
	at t.handleInstallOutput (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:498552)
	at e (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:560424)
	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
	at async /Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:582481
	at async t.withShowDetailsEvent (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:586100)
	at async /Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:557129
	at async T (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:555180)
	at async t.resolveWithLocalServer (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:556669)
	at async k (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:579620)
	at async t.resolve (/Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:583511)
	at async /Users/gaborcseh/.cursor/extensions/ms-vscode-remote.remote-ssh-0.113.1/out/extension.js:2:851172
[17:53:31.370] ------

I hope it helps.

ethanndickson

ethanndickson commented on Jun 3, 2025

@ethanndickson
Member

This has been a known issue with VSCode for a few years: microsoft/vscode-remote-release#5755

Using something like https://eternalterminal.dev/ to preserve the TCP connection between connection changes appears to resolve the issue.

added
upstreamIssues due to an upstream issue in VSCode or other dependency.
on Jun 3, 2025
DanielleMaywood

DanielleMaywood commented on Jun 4, 2025

@DanielleMaywood
Collaborator

Adding some context from some testing:

If I unplug my ethernet cable from my MacBook, it takes consistently around 18s to popup the "Cannot reconnect. Please reload the window."

If I close the lid of my MacBook whilst not plugged in to power, and wait roughly 15s, and then open it again, it will popup with "Cannot reconnect. Please reload the window."

I end up getting either one of two errors occur:

  • stderr> error: Get "https://<coder deployment>": dial tcp: lookup <coder deployment>: no such host

  • Unknown reconnection token (never seen). after successfully connecting to the host.

sachit-menon

sachit-menon commented on Jun 17, 2025

@sachit-menon

@ethanndickson could you say a little more on how to use ET to prevent this situation?

ethanndickson

ethanndickson commented on Jun 18, 2025

@ethanndickson
Member

@ethanndickson could you say a little more on how to use ET to prevent this situation?

We're also tracking how we at Coder can improve this experience in coder/coder#18101, including a PoC for Eternal Terminal

self-assigned this
on Jun 23, 2025
spikecurtis

spikecurtis commented on Jul 7, 2025

@spikecurtis

VS Code Server (server-main.js) has 2 kinds of connections:

  1. ManagementConnection
  2. ExtensionHostConnection

They are both websocket connections.

2025-07-03 11:18:49.872 [info] Extension host agent started.
2025-07-03 11:18:50.301 [info] [<unknown>][c21ec7a5][ExtensionHostConnection] New connection established.
2025-07-03 11:18:50.303 [info] [<unknown>][2987964b][ManagementConnection] New connection established.
2025-07-03 11:18:50.361 [info] [<unknown>][c21ec7a5][ExtensionHostConnection] <3602> Launched Extension Host Process.
2025-07-03 11:18:50.690 [info] ComputeTargetPlatform: linux-x64
2025-07-03 11:18:53.383 [info] ComputeTargetPlatform: linux-x64
2025-07-03 11:21:03.419 [info] [<unknown>][2987964b][ManagementConnection] The client has disconnected, will wait for reconnection 3h before disposing...
2025-07-03 11:23:49.873 [info] New EH opened, aborting shutdown
2025-07-03 11:35:33.283 [info] [<unknown>][2987964b][ManagementConnection] Another client has connected, will shorten the wait for reconnection 5m before disposing...
2025-07-03 11:35:33.286 [info] [<unknown>][c21ec7a5][ExtensionHostConnection] The client has reconnected.
2025-07-03 11:35:33.287 [info] [<unknown>][2987964b][ManagementConnection] The client has reconnected.
2025-07-03 11:35:33.289 [error] Error: Unexpected SIGPIPE
    at process.<anonymous> (file:///home/coder/.vscode-server/cli/servers/Stable-dfaf44141ea9deb3b4096f7cd6d24e00c147a4b1/server/out/server-main.js:191:1060)
    at process.emit (node:events:530:35)
2025-07-03 12:11:11.741 [info] [<unknown>][2987964b][ManagementConnection] The client has disconnected, will wait for reconnection 3h before disposing...
2025-07-03 12:28:38.699 [info] [<unknown>][2987964b][ManagementConnection] Another client has connected, will shorten the wait for reconnection 5m before disposing...
2025-07-03 12:28:38.700 [info] [<unknown>][2987964b][ManagementConnection] The client has reconnected.
2025-07-03 12:29:29.459 [info] [<unknown>][2987964b][ManagementConnection] The client has disconnected, will wait for reconnection 3h before disposing...
2025-07-03 12:33:40.804 [info] [<unknown>][c21ec7a5][ExtensionHostConnection] <3602> Extension Host Process exited with code: 0, signal: null.
2025-07-03 12:33:40.805 [info] Last EH closed, waiting before shutting down
2025-07-03 12:38:40.807 [info] Last EH closed, shutting down

When we get either one, the VS Code Server sets a 5 minute reconnection timeout on all connections of both types. If you reconnect, it cancels the timeout.

It appears that macOS briefly “sleepwalks” and allows VS Code Desktop to reconnect to the workspace (12:28:38 in the above log). Sometimes it doesn’t manage to reconnect to the ExtensionHostConnection, and the 5 minute timer starts. If you don’t wake your laptop within 5 minutes, the ExtensionHostConnection is closed (12:33:40 above), and you will have to “Reload Window” when you wake. When all ExtensionHostConnections are closed, then the VS Code Server shuts down.

I believe this mechanism is the source of the Unknown reconnection token (never seen) errors that we see after a relatively short sleep.

Even if you don’t trigger this timeout, there is a 3h “long” disconnection timeout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

upstreamIssues due to an upstream issue in VSCode or other dependency.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @csibe17@Mikescops@spikecurtis@Emyrk@matifali

      Issue actions

        VS Code keeps disconnecting if the client device sleeps · Issue #413 · coder/vscode-coder