VS CODE remote-ssh `code` command not working properly
Asked Answered
F

3

6

I connect to the remote server with vs code command invoked by CTRL+SHIFT+P Remote-SSH: Connect to Host.... Everything works fine. After some time when I try to open a new file from the vs-code terminal with the code command, I will get this error message:

/some/path/on/remote$ code some_existing_file.py                                                                                         
Unable to connect to VS Code server: Error in request.
Error: connect ENOENT /run/user/1006/vscode-ipc-789269cc-6026-4d15-8ca6-<i_changed_this>.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'connect',
  address: '/run/user/1001/vscode-ipc-789269cc-6026-4d15-8ca6-<i_changed_this>.sock'
}

Killing all running vs-code processes manually "solves" the problem. The occurence of this problem seems to be random. Sometimes it happens 3 times within an hour, sometimes just once per day.

vs-code version: 1.66.0

Any suggestion on how to solve this issue?

Flinn answered 6/4, 2022 at 8:52 Comment(3)
why use the terminal to open a fileLakshmi
@Lakshmi Too lazy to click. I hate using the file explorer GUI in general when I can use terminal as unified interface. Especially when you are browsing nested folders, TAB autocomplete is helpful.Carrel
you can use Ctrl+P and type part of the filename, or Ctrl+O, or Ctrl+Shift+E and type part of the filename, you have to enable workbench.list.keyboardNavigationLakshmi
S
3

I was having similar issue and error message when running code .

The solution worked for me was to remove everything under the HOME's .vscode-server directory

rm -rf ~/.vscode-server

Now do the code xxx command again should re-install the VS Code Server under the .vscode-server folder.

Skull answered 25/4, 2022 at 19:2 Comment(1)
I did this, and it removed all of the extensions/settings I had configured for the remote connection. The "code" command worked immediately afterwards, but it doesn't work today (I deleted the .vscode-server yesterday). I would prefer not having to reinstall my extensions each time; do you have any advice for that?Macur
P
0

Can you try this hack in your .bashrc or any other bash setup script you are using:

if [[ ! -z VSCODE_IPC_HOOK_CLI ]]; then
    REMOTE_CODE_BIN_PATH=$(echo $PATH | tr ':' '\n' | grep "/Users/steelphase/.vscode-server/bin/.*/bin")
    if [[ -d $REMOTE_CODE_BIN_PATH ]]; then
        NEW_PATH=$(echo $PATH | sed -e "s~:$REMOTE_CODE_BIN_PATH~~g")
        export PATH="$REMOTE_CODE_BIN_PATH:$NEW_PATH"
    fi
fi
Phasia answered 13/9, 2022 at 12:5 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Consistory
A
0

It's caused by the client connecting to an outdated socket. To simply solve this, just SSH into the server, and kill all processes for VS code:

ps -fu $USER | grep vscode | grep -v grep | awk '{print $2}' | xargs kill

Then you can restart VS code (with remote SSH) and try again.

Appendicitis answered 24/10 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.