vscode: Unable to connect to VS Code server: Error in request - ENOENT /run/user/1000/vscode-ipc-*.sock

This issue was originally reported in microsoft/vscode-remote-release#6997, but the cause was narrowed down to a file in this repo, src/vs/server/node/server.cli.ts.

Summary:

I’m occasionally but regularly seeing this error when using Remote SSH and running the code command in the built-in terminal.

Unable to connect to VS Code server: Error in request.
Error: connect ENOENT /run/user/1000/vscode-ipc-5cc265b0-6bec-4e0e-99c7-8fc48bccd7c4.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'connect',
  address: '/run/user/1000/vscode-ipc-5cc265b0-6bec-4e0e-99c7-8fc48bccd7c4.sock'
}

Here’s a temporary fix.

VSCODE_IPC_HOOK_CLI=$( lsof | grep $UID/vscode-ipc | awk '{print $(NF-1)}' | head -n 1 )

It searches for the first available VSCode IPC socket, gets its second to last column for the path to vscode-ipc-*.sock, and updates the relevant env variable.

After running the above line, the error no longer occurs.


It means the error is caused by that environment variable having a “stale” value, pointing at an old socket process which no longer exists.

https://github.com/microsoft/vscode/blob/f8ae10c8d05cf92f55c19b4937f0a5c5c0498778/src/vs/server/node/server.cli.ts#L372-L376

The env variable is passed to the http module for the option socketPath. When it’s an invalid value, http.request throws, “Error in request - ENOENT”.


The permanent solution seems to be: to check if VSCODE_IPC_HOOK_CLI is pointing to a living socket process, and if needed, refresh the value with the path to an available one.


  • VSCode Version: 1.69.2
  • Local OS Version: Darwin x64 18.2.0
  • Remote OS Version: Ubuntu 22.04 LTS
  • Remote Extension/Connection Type: SSH

Steps to Reproduce:

The error appears occasionally, maybe after host reboots or when Remote SSH reconnects.

  1. Open new window with Remote SSH
  2. Open terminal with CTRL/CMD+J
  3. Run code some-file.txt

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 16
  • Comments: 18

Most upvoted comments

Since I only have the issue in my Ubuntu 22.04 WSL environment and only when systemd is enabled, this superuser answer helped me to fix the missing /run/user/1000-dir (or whatever your user’s id may be) which is stored in XDG_RUNTIME_DIR and is used by vs code:

loginctl enable-linger $(whoami) 

After that I can observe on a freshly booted Ubuntu-Distro (wsl --shutdown in a windows-cmd and open new ubuntu shell), that /user/run/1000 exists and is already filled with some files in my case (I have wayland installed). This was not the case before that loginctl command.

Now I can execute code from within vs code just like I could without systemd.

I have just started seeing this when connected to wsl guests. I’m up-to-date (1.77.3). I have tried deleting ~/.vscode-server* while vscode is not running. doesn’t fix it.

in vscode wsl terminal:

$ code FILE
Unable to connect to VS Code server: Error in request.
Error: connect ENOENT /run/user/1000/vscode-ipc-cae625be-217b-4eb3-b699-7043b7a7a557.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'connect',
  address: '/run/user/1000/vscode-ipc-cae625be-217b-4eb3-b699-7043b7a7a557.sock'
}
$ ls -l /run/user
total 0
$ lsof | grep $UID/vscode-ipc | wc -l
0

not sure if relevant, but “Extension Host (Remote)” contains:

2023-04-15 10:56:10.729 [error] Error: listen EACCES: permission denied /run/user/1000/vscode-ipc-6241cd78-b726-4f61-b6bc-3966bc57ace9.sock
    at Server.setupListenHandle [as _listen2] (node:net:1313:21)
    at listenInCluster (node:net:1378:12)
    at Server.listen (node:net:1476:5)
    at O.g (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:101:188356)
    at new v (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:101:188271)
    at new O (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:101:190361)
    at S.j (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:84:1296)
    at S.createInstance (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:84:788)
    at E.pb (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:120:12418)
    at E.initialize (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:111:8811)
    at new d (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:115:1338)
    at c (/home/piersh/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/out/vs/workbench/api/node/extensionHostProcess.js:125:18641)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

wsl guest is CentOS7. systemd is NOT running. /run/user is empty.

it looks like vscode is incorrectly assuming the existence of some systemd-created directories.

creating the missing directory is a workaround for me:

sudo mkdir -p /run/user/$UID
sudo chown $UID /run/user/$UID

another option may be to ensure that the environment variable XDG_RUNTIME_DIR points to some directory you own.

@Domiii do I need to run it every time it breaks for me?

Which is literally every time I write something to VSCode terminal

Or can I slap it to ~/.profile or something? 🤔

Edit: Nvm, it doesn’t work for me no matter where and how I use it

I run ssh remote into a Linux system to use VSCode, occasionally run into this problem as well: typing in th terminal something like code some_file, the file is not opened in current VSCode, but the error message like “Error: connect ENOENT” shows. Usually after restarting VSCode the problem disappears.

Removing ~/.vscode-server is not a viable option, this directory usually has data larger than 1GB.

i’m seeing this consistently.

  • I see it every time i use the code command in the vscode terminal
  • i have the latest version
  • i have tried deleting `~/.vscode-server/
  • the temporary fix described above doesn’t work for me

before I apply the ‘fix’

Unable to connect to VS Code server: Error in request.
Error: connect EACCES /mnt/wslg/runtime-dir/vscode-ipc-596ebb83-bf0f-4710-ac8e-d6442b87d8a6.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1157:16) {
  errno: -13,
  code: 'EACCES',
  syscall: 'connect',
  address: '/mnt/wslg/runtime-dir/vscode-ipc-596ebb83-bf0f-4710-ac8e-d6442b87d8a6.sock'
}

output when i apply the ‘fix’

$ VSCODE_IPC_HOOK_CLI=$( lsof | grep $UID/vscode-ipc | awk '{print $(NF-1)}' | head -n 1 )
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/acpid/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/acpid/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/allowlist/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/allowlist/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/binfmt/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/binfmt/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/container-filesystem/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/container-filesystem/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/devenv-service/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/devenv-service/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/diagnose/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/diagnose/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/dns-forwarder/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/dns-forwarder/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/docker/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/docker/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/http-proxy/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/http-proxy/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/kmsg/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/kmsg/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/nat/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/nat/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/rngd/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/rngd/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/sntpc/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/sntpc/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/socks/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/socks/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/syn-filter/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/syn-filter/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/trim-after-delete/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/trim-after-delete/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/volume-contents/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/volume-contents/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/vpnkit-forwarder/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/vpnkit-forwarder/rootfs
      Output information may be incomplete.
lsof: WARNING: can't stat() tmpfs file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/vpnkit-tap-vsockd/tmp
      Output information may be incomplete.
lsof: WARNING: can't stat() overlay file system /mnt/wsl/docker-desktop-data/version-pack-data/community/mount-services-cache/entries/services.tar/eae320734be940e610955446282e0484c6d4bc072f63eb699ff02f3f1dadef28/containers/services/vpnkit-tap-vsockd/rootfs
      Output information may be incomplete.

and when i run the command again-

Command is only available in WSL or inside a Visual Studio Code terminal.

so that’s… something.

not sure who invited docker-desktop to the party.

for context- I first saw this after migrating to the Windows Store WSL2