post

Fixing VSCode when it keeps dropping ssh connections

I really like VSCode, and I use the ssh plugin to edit code on remote machines, but recently the ssh connection has been dropping all of the time, even when I’m editing code on another machine that’s on the same local network.

I’ve updated both my OS and VSCode multiple times recently, so I thought some bug had slipped into one of the updates and that was causing a problem. I was somewhat correct. It seems that VSCode keeps a cache of data and code on the remote machine, and something in a VSCode update was trying to do something using the bits in the old cache data that was no longer supported.

To fix the problem I just removed the cache as follows:

  • Exit completely out of VSCode so that no VSCode processes are running. Force quit if you have to.
  • ssh to the remote machine(s) and delete the ~/.vscode-server directory with rm -Rf ~/.vscode-server/
  • If you get any “cannot remove [file]: Device or resource busy” errors then look for stuck processes:
    lsof | grep $HOME/.vscode-server | awk '{ print $2 }' | sort -u
    … then kill those processes, then trying removing the directory again.
  • Restart VSCode.

Once I did this all of my connection problems disappeared.

Hope you find this useful.

Share Button