Bug 1098042 - getaddrinfo return EAI_NONAME instead of EAI_AGAIN in case the DNS query times out
Summary: getaddrinfo return EAI_NONAME instead of EAI_AGAIN in case the DNS query time...
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: glibc
Version: 7.0
Hardware: Unspecified
OS: Unspecified
Target Milestone: rc
: ---
Assignee: Carlos O'Donell
QA Contact: Arjun Shankar
Depends On:
Blocks: 1205796 1110703 1191023
TreeView+ depends on / blocked
Reported: 2014-05-15 07:18 UTC by Siddhesh Poyarekar
Modified: 2015-11-19 04:14 UTC (History)
12 users (show)

Fixed In Version: glibc-2.17-89.el7
Doc Type: Bug Fix
Doc Text:
The getaddrinfo function correctly returns EAI_AGAIN for AF_INET and AF_INET6 queries that have timed out. However, for AF_UNSPEC, a defect in the library caused EAI_NONAME to be returned. Applications could incorrectly interpret EAI_NONAME as there being no result, when they should have tried the query again. The defect has been corrected such that an EAI_AGAIN is returned to the caller instead of EAI_NONAME.
Clone Of: 1044628
Last Closed: 2015-11-19 04:14:13 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2015:2199 0 normal SHIPPED_LIVE Moderate: glibc security, bug fix, and enhancement update 2015-11-19 08:04:22 UTC
Sourceware 16849 0 P2 RESOLVED getaddrinfo returns EAI_NONAME instead of EAI_AGAIN for network failures 2021-02-06 14:58:40 UTC

Description Siddhesh Poyarekar 2014-05-15 07:18:59 UTC
Description of problem:
getaddrinfo returns EAI_NONAME when it should EAI_AGAIN, like when DNS query times out.
It is also a question what should it return when no DNS is configured in resolv.conf and the hostname is also not in /etc/hosts; currently it rerurns also EAI_NONAME.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
[root@rhel6 audit]# cat getaddrinfo.c 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>

lookup_host (const char *host)
  struct addrinfo hints, *res;
  int errcode;
  char addrstr[100];
  void *ptr;

  memset (&hints, 0, sizeof (hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags |= AI_CANONNAME;

  errcode = getaddrinfo (host, NULL, &hints, &res);
  if (errcode != 0)
      printf ("Error num: %d\n", errcode);
      printf ("Error def: %s\n", gai_strerror(errcode));
      perror ("getaddrinfo");
      return -1;

  printf ("Host: %s\n", host);
  while (res)
      inet_ntop (res->ai_family, res->ai_addr->sa_data, addrstr, 100);

      switch (res->ai_family)
        case AF_INET:
          ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr;
        case AF_INET6:
          ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr;
      inet_ntop (res->ai_family, ptr, addrstr, 100);
      printf ("IPv%d address: %s (%s)\n", res->ai_family == PF_INET6 ? 6 : 4,
              addrstr, res->ai_canonname);
      res = res->ai_next;

  return 0;

main (int argc, char *argv[])
  if (argc < 2)
    exit (1);
  return lookup_host (argv[1]);

[root@rhel6 audit]# 
[root@rhel6 audit]# 
[root@rhel6 audit]# 
[root@rhel6 audit]# gcc -o getaddrinfo getaddrinfo.c
[root@rhel6 audit]# ./getaddr
getaddr      getaddrinfo  
[root@rhel6 audit]# cat /etc/resolv.conf
[root@rhel6 audit]# cat /var/named/bbb 
$TTL    86400 ; 24 hours could have been written as 24h or 1d
$ORIGIN bbb.net.
@  1D  IN    SOA rhel6.bbb.net.   hostmaster.bbb.net. (
                  2002022401 ; serial
                  3H ; refresh
                  15 ; retry
                  1w ; expire
                  3h ; minimum
           IN  NS     rhel6.bbb.net. ; in the domain
           IN  A  ;name server definition
rhel6      IN  A  ;name server definition
rhel61     IN  A ;name server definition

[root@rhel6 audit]# 
[root@rhel6 audit]# ./getaddrinfo rhel61.bbb.net
Host: rhel61.bbb.net
IPv4 address: (rhel61.bbb.net)
[root@rhel6 audit]# 
[root@rhel6 audit]# iptables -A OUTPUT -m udp -p udp --sport 53 -j REJECT
[root@rhel6 audit]# ./getaddrinfo rhel61.bbb.net
Error num: -2
Error def: Name or service not known
getaddrinfo: Connection timed out
[root@rhel6 audit]# 
[root@rhel6 audit]# rpm -q glibc
[root@rhel6 audit]#

Actual results:

Expected results:

Comment 13 errata-xmlrpc 2015-11-19 04:14:13 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.


Note You need to log in before you can comment on or make changes to this bug.