nix-community / napalm

Support for building npm packages in Nix and lightweight npm registry [maintainer=?]
MIT License
104 stars 17 forks source link

In some envrionemtns fails with getaddrinfo ENOTFOUND localhost #31

Closed kevincox closed 3 years ago

kevincox commented 3 years ago

Sorry for the weird issue, but I don't really know where to start debugging. My build fails on GitLab (no sandboxing) with a really strange error. Builds on my laptop NixOS (with or without sandboxing) are fine. Building on my laptop using the local GitLab runner does fail.

npm WARN kevincox-web-compiler@0.0.0 No repository field.
npm WARN kevincox-web-compiler@0.0.0 No license field.
npm verb type system
npm verb stack FetchError: request to http://localhost:46645/abab failed, reason: getaddrinfo ENOTFOUND localhost
npm verb stack     at ClientRequest.<anonymous> (/nix/store/nm15xz8bigq33d3x8r8lfrdlnvspmjrm-nodejs-14.15.4/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm verb stack     at ClientRequest.emit (events.js:315:20)
npm verb stack     at Socket.socketErrorListener (_http_client.js:469:9)
npm verb stack     at Socket.emit (events.js:315:20)
npm verb stack     at emitErrorNT (internal/streams/destroy.js:106:8)
npm verb stack     at emitErrorCloseNT (internal/streams/destroy.js:74:3)
npm verb stack     at processTicksAndRejections (internal/process/task_queues.js:80:21)
npm verb cwd /tmp/nix-build-kevincox-web-compiler-0.0.0.drv-0/kevincox-web-compiler
npm verb Linux 4.19.78-coreos
npm verb argv "/nix/store/nm15xz8bigq33d3x8r8lfrdlnvspmjrm-nodejs-14.15.4/bin/node" "/nix/store/nm15xz8bigq33d3x8r8lfrdlnvspmjrm-nodejs-14.15.4/bin/npm" "install" "--loglevel" "verbose"
npm verb node v14.15.4
npm verb npm  v6.14.10
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to http://localhost:46645/abab failed, reason: getaddrinfo ENOTFOUND localhost
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
npm verb exit [ 1, true ]https://gitlab.com/kevincox/nix-ci/-/blob/v1/default.nix
npm timing npm Completed in 5303ms

There is a localhost entry in the hosts file for both IPv4 and IPv6.

$ cat /etc/hosts
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.0.1   0hshit.hopto.org
127.0.0.1   daymndaymn.myftp.org
127.0.0.1   loba.webhop.me
172.17.0.3  runner-fa6cab46-project-24138563-concurrent-0

Links:

This seems to be stemming from the custom image that the build runs in but I haven't been able to identify the cause yet. https://gitlab.com/kevincox/nix-ci/-/blob/v1/default.nix

I'm opening this bug to help anyone else seeing a similar problem and ideally collect debugging tips and information. Feel free to close if you consider it off-topic.

One other question: Do you think it would be possible to use a loopback IP directly instead of localhost? It would remove a dependency in the stack even if I should get a proper environment set up.

kevincox commented 3 years ago

I found the issue. I needed an /etc/nsswitch.conf. Without it node was going directly to the DNS server.

Still worth considering using an IP instead of a hostname, but my issue is resolved.