VScode SSH extension keeps disconnecting after moving to a new location

25.9k views Asked by At

I recently moved to a different country, but I work remotely and therefore I thought that my workspace wouldn't be interrupted. However, now that I'm trying to connect to my workspace through ssh in vscode, the connection keeps disconnecting. I connect to the workspace through the VPN my workspace provides, and while I can connect to the linux box I work in via ssh, I cannot connect to it through vscode-remote-ssh extension like I did for the past few months. Nothing has changed in terms of settings on my computer. I attached the output vscode provides when I tried to connect below (this is the output from the reconnection attempt but the first connection attempt looks exactly the same).

[15:36:11.086] ------




[15:36:11.086] SSH Resolver called for "ssh-remote+203.0.113.0", attempt 2, (Reconnection)
[15:36:11.087] SSH Resolver called for host: 203.0.113.0
[15:36:11.087] Setting up SSH remote "203.0.113.0"
[15:36:11.091] Using commit id "e5e9e69aed6e1984f7499b7af85b3d05f9a6883a" and quality "stable" for server
[15:36:11.092] Install and start server if needed
[15:36:11.096] Using SSH config file "C:\Users\windowsUser\.ssh\config"
[15:36:11.096] Running script with connection command: ssh -T -D 53043 -F "C:\Users\windowsUser\.ssh\config" 203.0.113.0 bash
[15:36:11.101] Terminal shell path: C:\Windows\System32\cmd.exe
[15:36:11.240] > 
[15:36:11.240] Got some output, clearing connection timeout
[15:36:13.669] > [email protected]'s password:
[15:36:13.670] Showing password prompt
[15:36:29.329] Got password response
[15:36:29.330] "install" wrote data to terminal: "*******"
[15:36:29.358] > 
> 
[15:36:31.047] > 3a294560e95d: running
> Acquiring lock on /home/linuxUser/.vscode-server/bin/e5e9e69aed6e1984f7499b7af85b3
> d05f9a6883a/vscode-remote-lock.linuxUser.e5e9e69aed6e1984f7499b7af85b3d05f9a6883a
> 
[15:36:31.073] > Found existing installation at /home/linuxUser/.vscode-server/bin/e5e9e69aed6e1984
> f7499b7af85b3d05f9a6883a...
> Found running server...
> 
> *
> * Reminder: You may only use this software with Visual Studio family products,
> * as described in the license (https://go.microsoft.com/fwlink/?linkid=2077057)
> *
> 
> Checking server status on port 34103 with wget
> 
[15:36:31.108] > 3a294560e95d: start
> 
[15:36:31.391] > sshAuthSock====
> listeningOn==34103==
> osReleaseId==ubuntu==
> arch==x86_64==
> webUiAccessToken====
> tmpDir==/run/user/1000==
> platform==linux==
> 3a294560e95d: end
> 
[15:36:31.391] Received install output: 
sshAuthSock====
listeningOn==34103==
osReleaseId==ubuntu==
arch==x86_64==
webUiAccessToken====
tmpDir==/run/user/1000==
platform==linux==

[15:36:31.392] Remote server is listening on 34103
[15:36:31.392] Parsed server configuration: {"remoteListeningOn":{"port":34103},"osReleaseId":"ubuntu","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","tmpDir":"/run/user/1000","platform":"linux"}
[15:36:31.393] Starting forwarding server. localPort 53048 -> socksPort 53043 -> remotePort 34103
[15:36:31.395] Forwarding server listening on 53048
[15:36:31.395] Waiting for ssh tunnel to be ready
[15:36:31.396] Tunneled 34103 to local port 53048
[15:36:31.396] Resolved "ssh-remote+203.0.113.0" to "127.0.0.1:53048"
[15:36:31.397] [Forwarding server 53048] Got connection 0
[15:36:31.402] ------




[15:36:31.430] [Forwarding server 53048] Got connection 1
[15:36:31.431] [Forwarding server 53048] Got connection 2

The connection hangs on [Forwarding server 53048] Got connection 2 for a few seconds before disconnecting me and repeating this message (and asking for password again). I tried removing the .vscode-server file from the linux computer, which is then recreated right away but it still doesn't let me connect. I also tried changing the timeout in the vscode settings but this also did nothing. I am unsure why this would happen after simply physically moving the computer from one place to another but remaining on the same vpn, and why I would still be able to connect with regular ssh but just not through the vscode-remote ssh extension.

3

There are 3 answers

2
Martin On

I had the same exact issue, and for me. I dont have a resolution but a crappy workaround - reboot the far machine. im running ubuntu 20.04 and once i rebooted, then i can connect from visual studio and connection stays up, BUT once i close the VSC and restart, then i see this issue again, and again i have to reboot the far machine.

EDIT: later i discovered that stopping the sshd daemon with systemctl start/stop sshd also helps this situation - so no need to reboot

2
kachar On

You might try ssh manually to the server and delete the remote server folder which makes VSCode download it again from scratch.

This has helped me today:

rm -rf ~/.vscode-server/
rm -rf ~/.vscode-remote/

The suggestion comes from the following discussion: https://github.com/microsoft/vscode-remote-release/issues/2513


You might also wanna check if your new network IP is allowed in the target group of the server.

0
softwareartisan On

This issue is due to a hard coded 20 second timeout in the protocol between the vscode client and the remote server. This is discussed in detail here: https://github.com/microsoft/vscode-remote-release/issues/7497. No fixes for this yet and will hopefully be fixed soon by making this timeout configurable (to allow overcoming these disconnects).