Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Error: getaddrinfo ENOTFOUND localhost #44003

Closed
AdamMajer opened this issue Jul 26, 2022 · 12 comments · Fixed by #44083
Closed

test: Error: getaddrinfo ENOTFOUND localhost #44003

AdamMajer opened this issue Jul 26, 2022 · 12 comments · Fixed by #44083

Comments

@AdamMajer
Copy link
Contributor

Version

18.6.0

Platform

openSUSE Tumbleweed

Subsystem

No response

What steps will reproduce the bug?

Currently the failures are visible in the current build log,

https://build.opensuse.org/public/build/devel:languages:nodejs/openSUSE_Tumbleweed/x86_64/nodejs18/_log

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

not ok 1995 parallel/test-net-socket-connect-without-cb
  ---
  duration_ms: 0.506
  severity: fail
  exitcode: 1
  stack: |-
    node:events:491
          throw er; // Unhandled 'error' event
          ^
    
    Error: getaddrinfo ENOTFOUND localhost
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:111:26)
    Emitted 'error' event on Socket instance at:
        at emitErrorNT (node:internal/streams/destroy:151:8)
        at emitErrorCloseNT (node:internal/streams/destroy:116:3)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      errno: -3008,
      code: 'ENOTFOUND',
      syscall: 'getaddrinfo',
      hostname: 'localhost'
    }
    
    Node.js v18.6.0
  ...

...

not ok 2000 parallel/test-net-socket-ready-without-cb
  ---
  duration_ms: 0.507
  severity: fail
  exitcode: 1
  stack: |-
    node:events:491
          throw er; // Unhandled 'error' event
          ^
    
    Error: getaddrinfo ENOTFOUND localhost
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:111:26)
    Emitted 'error' event on Socket instance at:
        at emitErrorNT (node:internal/streams/destroy:151:8)
        at emitErrorCloseNT (node:internal/streams/destroy:116:3)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      errno: -3008,
      code: 'ENOTFOUND',
      syscall: 'getaddrinfo',
      hostname: 'localhost'
    }
    
    Node.js v18.6.0
  ...

not ok 2591 parallel/test-tcp-wrap-listen
  ---
  duration_ms: 0.818
  severity: fail
  exitcode: 1
  stack: |-
    (node:18408) internal/test/binding: These APIs are for internal testing only. Do not use them.
    (Use `node18 --trace-warnings ...` to show where the warning was created)
    node:events:491
          throw er; // Unhandled 'error' event
          ^
    
    Error: getaddrinfo ENOTFOUND localhost
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:111:26)
    Emitted 'error' event on Socket instance at:
        at emitErrorNT (node:internal/streams/destroy:151:8)
        at emitErrorCloseNT (node:internal/streams/destroy:116:3)
        at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
      errno: -3008,
      code: 'ENOTFOUND',
      syscall: 'getaddrinfo',
      hostname: 'localhost'
    }
    
    Node.js v18.6.0
  ...

Additional information

> cat /etc/hosts
127.0.0.1 localhost
#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               "named" name server.
# Syntax:
#    
# IP-Address  Full-Qualified-Hostname  Short-Hostname
#

127.0.0.1       localhost
# fallback hostname used by NetworkManager
127.0.0.1       localhost.localdomain

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback

fe00::0         ipv6-localnet

ff00::0         ipv6-mcastprefix
ff02::1         ipv6-allnodes
ff02::2         ipv6-allrouters
ff02::3         ipv6-allhosts

and resolv.conf doesn't exist. All other test cases that use localhost are passing, as expected.

@kvakil
Copy link
Contributor

kvakil commented Jul 27, 2022

curious what you see when doing strace. On Ubuntu I see the following:

$ strace -ff ./node test/parallel/test-tcp-wrap-listen.js |& grep localhost
[pid  4385] read(19, "127.0.0.1 localhost\n\n# The follo"..., 4096) = 221
[pid  4385] sendto(19, "\362*\1 \0\1\0\0\0\0\0\1\tlocalhost\3ec2\10inter"..., 51, MSG_NOSIGNAL, NULL, 0) = 51
[pid  4385] recvfrom(19, "\362*\201\203\0\1\0\0\0\0\0\1\tlocalhost\3ec2\10inter"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.53")}, [28 => 16]) = 51
[pid  4385] sendto(19, "Uk\1 \0\1\0\0\0\0\0\1\tlocalhost\0\0\34\0\1\0\0)\4\260"..., 38, MSG_NOSIGNAL, NULL, 0) = 38
[pid  4385] recvfrom(19, "Uk\205\240\0\1\0\1\0\0\0\1\tlocalhost\0\0\34\0\1\300\f\0\34\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.53")}, [28 => 16]) = 66

@theanarkh
Copy link
Contributor

I get this error sometimes on my pc, but not always.

@bnoordhuis
Copy link
Member

ENOTFOUND is a synthetic error that node fabricates when it doesn't get an answer back from getaddrinfo(3), it's not a real operating system-level error. Reasons include running out of file descriptors in libc (not visible to node), not getting back a response from the DNS server, etc. It's basically a catch-all.

@AdamMajer
Copy link
Contributor Author

In this case, there is no DNS server and it works with other tests...

strace shows nothing. This is only a problem since about 18.2.0 and not before and not in any other released line. And I only see it in a VM build environment and not in a chroot (at least it disappeared there) which is very strange.

I will try to bisect the issue.

@bnoordhuis
Copy link
Member

You mean v18.1.0 works? There are no changes between the two that seem like likely culprits. I'm interested to see what bisect turns up.

@AdamMajer
Copy link
Contributor Author

So, the bisect ended up on 70b516e which is #43054 . Looking at the pull request, it kind of makes sense this is the one as the tests in question are explicitly skipped on some platforms.

https://github.com/nodejs/node/pull/43054/files#diff-5ba63fa1f910a3ec440b5174993719278ddca69569c0159e2c782173af190602

The test is reproducible every time on openSUSE:Tumbleweed build VM. I can't reproduce it outside of it on a workstation, but in the VM with no networking connections and only a hosts file to resolve localhost to ipv6 and ipv4, it reproduces every time.

I will try to look more closely what is actually failing here.

@AdamMajer
Copy link
Contributor Author

This was introduced in 18.4.0. I mistyped earlier the versions. 18.2.0 still passed

@kapouer
Copy link
Contributor

kapouer commented Aug 1, 2022

Is there no network interface at all, no loopback ?

AdamMajer added a commit to AdamMajer/node that referenced this issue Aug 1, 2022
As a consequence of nodejs#43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: nodejs#44003
@AdamMajer
Copy link
Contributor Author

So, I've learned something about debugging node over last few days :-) But I did find the problem.

> NODE_DEBUG=net ./node18 test/parallel/test-net-socket-ready-without-cb.js
NET 1834: setupListenHandle ::1 0 6 false undefined
NET 1834: setupListenHandle: create a handle
NET 1834: bind to ::1
{ address: '::1', family: 'IPv6', port: 32841 }
NET 1834: pipe false undefined
NET 1834: connect: find host localhost
NET 1834: connect: dns options { family: 'IPv6', hints: 32 }

The problem is that family is set to a string, which causes hints to be set to 32 which means AI_ADDRCONFIG and then address resolution fails.

On a network connected device, this passes.

Why? We can look at the manpage for getaddrinfo

If hints.ai_flags includes the AI_ADDRCONFIG flag, then IPv4 addresses are returned in the list pointed to by res only if the local system has at least one IPv4 address configured, and IPv6 addresses are returned only if the local system has at least one IPv6 address configured. The loopback address is not considered for this case as valid as a configured address. This flag is useful on, for example, IPv4-only systems, to ensure that getaddrinfo() does not return IPv6 socket addresses that would always fail in connect(2) or bind(2).

This is why these tests fail every time when you have a loopback interface as the only network interface active. They will pass if you have other network interfaces active.

AdamMajer added a commit to AdamMajer/node that referenced this issue Aug 1, 2022
As a consequence of nodejs#43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results in wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: nodejs#44003
nodejs-github-bot pushed a commit that referenced this issue Aug 3, 2022
As a consequence of #43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results in wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: #44003
PR-URL: #44083
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
danielleadams pushed a commit that referenced this issue Aug 16, 2022
As a consequence of #43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results in wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: #44003
PR-URL: #44083
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
ruyadorno pushed a commit that referenced this issue Aug 23, 2022
As a consequence of #43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results in wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: #44003
PR-URL: #44083
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Fyko pushed a commit to Fyko/node that referenced this issue Sep 15, 2022
As a consequence of nodejs#43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results in wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: nodejs#44003
PR-URL: nodejs#44083
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
juanarbol pushed a commit that referenced this issue Oct 3, 2022
As a consequence of #43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results in wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: #44003
PR-URL: #44083
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
juanarbol pushed a commit that referenced this issue Oct 4, 2022
As a consequence of #43014 ,
server sockets and others, once connected, report string family
names. But when feeding these to Socket.connect(), it passes
these to host resolution with a string for family while a numeric
family is expected internally. This results in wrong hints flags
to be set and resolution to fail.

As solution, is to add ability to handle both numeric and string
family names when doing lookup and connect.

Fixes: #44003
PR-URL: #44083
Reviewed-By: Paolo Insogna <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@Daniel-quintero1
Copy link

original: Error: getaddrinfo ENOTFOUND undefined
GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'undefined'

el error aca como podria solucionar? me arroja basicamente que no encuentra mi localhost.

@kyungseopk1m
Copy link

In my case, the same error occurred when I made a request to a server address other than localhost, but it turned out that there was no problem with me and the problem was with the server.
Additionally, requests intermittently repeated success and failure.

@haojieZzz
Copy link

I add the line in my hosts file and it worked;

127.0.0.1 localhost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants