6

After I upgraded my container to the commit from plutus pioneer programm lecture 3 the VsCode server won't spawn anymore in the dev container.

VSCode tells

could not fetch remote environment

Failed to connect to the remote extension host server (Error: WebSocket close with status code 1006)

The console tells something about getaddrinfo ENOTFOUND localhost:

*
* Visual Studio Code Server
*
* Reminder: You may only use this software with Visual Studio family products,
* as described in the license https://aka.ms/vscode-remote/license
*

Extension host agent listening on 38293

[4406 ms] Start: Run in container: echo 38293 >/root/.vscode-server/data/Machine/.devport
[4408 ms] 
[4409 ms] 
[4409 ms] Port forwarding for container port 38293 starts listening on local port.
[4410 ms] Port forwarding local port 38293 to container port 38293
[4421 ms] Port forwarding connection from 65417 > 38293 > 38293 in the container.
[4421 ms] Start: Run: wsl -d Ubuntu -e /bin/sh -c cd '/home/wutze/workspace/plutus-pioneer-program' && DISPLAY='1' ELECTRON_RUN_AS_NODE='1' SSH_ASKPASS='c:\Users\wutze\.vscode\extensions\ms-vscode-remote.remote-containers-0.177.0\scripts\ssh-askpass.bat' VSCODE_SSH_ASKPASS_NODE='C:\Users\wutze\AppData\Local\Programs\Microsoft VS Code\Code.exe' VSCODE_SSH_ASKPASS_MAIN='c:\Users\wutze\.vscode\extensions\ms-vscode-remote.remote-containers-0.177.0\dist\common\sshAskpass.js' VSCODE_SSH_ASKPASS_HANDLE='\\.\pipe\ssh-askpass-32ff11722b3a35f061eaff56993e1deab5d0eea2-sock' DOCKER_CONTEXT='default' VSCODE_SSH_ASKPASS_COUNTER='14' docker 'exec' '-i' '-u' 'root' '-e' 'VSCODE_REMOTE_CONTAINERS_SESSION=c2909e18-9ccb-4e7f-9ffc-a2aed511465e1620332517761' '73ba0ca7a6a532509c5d66df05fbfd39d8174e93661432cdbb28933efd49c768' '/root/.vscode-server/bin/cfa2e218100323074ac1948c885448fdf4de2a7f/node' '-e' '
[4554 ms] [20:22:02] Extension host agent started.
[4580 ms] Installing extensions...
[4750 ms] Start: Run in container: command -v git >/dev/null 2>&1 && git config --global credential.helper '!f() { /root/.vscode-server/bin/cfa2e218100323074ac1948c885448fdf4de2a7f/node /tmp/vscode-remote-containers-b989d5aac79afe5555725461b56f804a3d10bef0.js $*; }; f' || true
[4755 ms] 
[4756 ms] 
[4931 ms] Port forwarding 65417 > 38293 > 38293 stderr: Error: getaddrinfo ENOTFOUND localhost
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
[4932 ms] Port forwarding 65417 > 38293 > 38293 stderr: Remote close with error
[4955 ms] Port forwarding 65417 > 38293 > 38293: Local close
[4956 ms] Port forwarding 65417 > 38293 > 38293 terminated by extension with code 1 and signal null.

Any ideas what's gooing wrong? The commit from lecture 1 worked.

I already checked all hosts files from windows, wsl and the dev-container, all contain the localhost 127.0.0.1 entry.

I also opened a cli in the dev container and startded node with /root/.vscode-server/bin/cfa2e218100323074ac1948c885448fdf4de2a7f/node and it also fails

> dns.lookup('localhost', {hints: dns.ADDRCONFIG|dns.V4MAPPED}, console.log)
GetAddrInfoReqWrap {
  callback: [Function: log],
  family: 0,
  hostname: 'localhost',
  oncomplete: [Function: onlookup]
}
> Error: getaddrinfo ENOTFOUND localhost
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
    at GetAddrInfoReqWrap.callbackTrampoline (internal/async_hooks.js:131:14) {
  errno: -3007,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'localhost'

for another hostname it works:

> dns.lookup('www.google.de', {hints: dns.ADDRCONFIG|dns.V4MAPPED}, console.log)
GetAddrInfoReqWrap {
  callback: [Function: log],
  family: 0,
  hostname: 'www.google.de',
  oncomplete: [Function: onlookup]
}
> null 142.250.184.227 4

It is definitly this commit in plutus because if I checkout the one before it suddenly works again:

SHA-1: 5dbd3b833b40217cb1a63d4f52351ae8876ba86c

* adds a non-root user for use in the devcontainer (#2956)

* adds a non-root user for use in the devcontainer

* remove un-needed files

* .cabal folder permissions for volume mapping

3 Answers 3

5

Ok, I found the issue, someone removed the nsswitch file here: https://github.com/input-output-hk/plutus/commit/5dbd3b833b40217cb1a63d4f52351ae8876ba86c

The file tells the system to lookup the hosts file, but without the file, it won't.

So, I just opened a my wsl-ubuntu and created the file in my home folder:

vi ~/nsswitch.conf

and put the content

passwd:    files mymachines systemd
group:     files mymachines systemd
shadow:    files

hosts:     files mymachines dns myhostname
networks:  files

ethers:    files
services:  files
protocols: files
rpc:       files

Now, I changed the devcontainer.json so it mounts the file:

{
    "name": "Plutus Starter Project",
    "image": "plutus-devcontainer:latest",

    "remoteUser": "plutus",

    "mounts": [
        // This shares cabal's remote repository state with the host. We don't mount the whole of '.cabal', because
        // 1. '.cabal/config' contains absolute paths that will only make sense on the host, and
        // 2. '.cabal/store' is not necessarily portable to different version of cabal etc.
        "source=${localEnv:HOME}/.cabal/packages,target=/home/plutus/.cabal/packages,type=bind,consistency=cached",
        "source=${localEnv:HOME}/nsswitch.conf,target=/etc/nsswitch.conf,type=bind,consistency=cached",
    ],

    "settings": {
        // Note: don't change from bash so it runs .bashrc
        "terminal.integrated.shell.linux": "/bin/bash"
    },
    
    // IDs of extensions inside container
    "extensions": [
        "haskell.haskell"
    ],
}

Now I'm back in business

5
  • Thank you so much ! I had the same problem... Commented May 12, 2021 at 18:59
  • does the fix work for you?
    – wutzebaer
    Commented May 12, 2021 at 19:02
  • 1
    Yes ! it worked! Commented May 13, 2021 at 12:19
  • Thanks! When in Windows use the variable USERPROFILE instead of HOME when mounting.
    – Gijs
    Commented Sep 14, 2021 at 18:25
  • Thanks! You saved my life. Commented Oct 15, 2021 at 2:20
2

This is a follow-up to the answer from wutzebaer.

The Cardano team has since patched the repository to address the issue. They did not, however, revert the problem file to its previous working state. Instead they re-introduced the file using a different method and with different contents. Namely, the new nsswitch.conf file only contains hosts: dns file

Apparently, this seems to have solved the problem for many, but there are still some cases where it is failing.

The workaround that wutzebaer posted still works, but I have a few improvements:

  1. The nsswitch.conf file only needs to contain.

    hosts: file dns 
    

    Note that the order is file dns, not dns file

    The reordering of these properties is the new fix that needs to be made officially.

  2. The nsswitch.conf file should be stored in the project where it can be committed to the repository, not in the user's home directory. In this way, the project remains self-contained and not dependent on any user-specific environment.

The new instructions:

  1. create <project folder>/.devcontainer/nsswitch.conf with the contents:
    hosts: file dns
    
  2. Update the devcontainer.json to mount the nsswitch.conf in the container.
    {
        "name": "Plutus Starter Project",
        "image": "docker.io/inputoutput/plutus-starter-devcontainer:v1.0.10",
    
        "remoteUser": "plutus",
    
        "mounts": [
            // This shares cabal's remote repository state with the host. We don't mount the whole of '.cabal', because
            // 1. '.cabal/config' contains absolute paths that will only make sense on the host, and
            // 2. '.cabal/store' is not necessarily portable to different version of cabal etc.
            "source=${localEnv:HOME}${localEnv:USERPROFILE}/.cabal/packages,target=/home/plutus/.cabal/packages,type=bind,consistency=cached",
            "source=${localWorkspaceFolder}/.devcontainer/nsswitch.conf,target=/etc/nsswitch.conf,type=bind,consistency=cached",
        ],
    
        "settings": {
           // Note: don't change from bash so it runs .bashrc
            "terminal.integrated.shell.linux": "/bin/bash"
        },
    
        // IDs of extensions inside container
        "extensions": [
            "haskell.haskell"
        ],
    }
    

For bonus points, note that I have also modified the other mount configuration "source=${localEnv:HOME}${localEnv:USERPROFILE}/.cabal/packages,target=/home/plutus/.cabal/packages,type=bind,consistency=cached"

changing source=${localEnv:HOME}/.cabal/packages

to source=${localEnv:HOME}${localEnv:USERPROFILE}/.cabal/packages

This is because the HOME environment variable is not a standard variable in Windows, although many people may have it defined due to various (often 'nix-like) software installs. Microsoft's recommendation is to pair ${localEnv:HOME}${localEnv:USERPROFILE} since HOME is only valid for Linux and USERPROFILE is only valid for Windows.

In my case, the HOME variable is not defined, so spinning up the container would give me mount errors because it was looking for /.cabal/packages instead of C:\Users\FuzzyLogic/.cabal/packages

0

Good news, and bad news. Bad first.

I just tried the single line of config, and sadly it doesn't work for me. No matter which way I had the files or dns. Specifically NEITHER of these configuration lines worked: hosts: file dns hosts: dns file

When I used the single line nsswitch.conf configuration I just used "Rebuild Container" in VS Code and the ENOTFOUND error messages continued to appear.

The GOOD NEWS:

Upon using the larger configuration (again, thanks to wutzebaer) - this worked; well, at least I got what looks to be a working environment.

:-)

1
  • Welcome to Cardano SE! As a new user be sure to take the Tour.
    – gRebel
    Commented Jan 14, 2022 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.