This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug network/13904] New: getaddrinfo does two identical queries, breaks dns round robin with two hosts

             Bug #: 13904
           Summary: getaddrinfo does two identical queries, breaks dns
                    round robin with two hosts
           Product: glibc
           Version: 2.11
            Status: NEW
          Severity: normal
          Priority: P2
         Component: network
    Classification: Unclassified

The host '' has two ipv4 ips.  when using ping,
each ping execution alternates hosts, and strace shows only one dns query is

however, another program using getaddrinfo() does not get the same rotation. 
It appears that getaddrinfo inexplicably sends a redundant dns query (only
thing different is transaction id), thus causing an entire rotation through
both hosts each time.  The returned ip will always be fairly constant - it will
be the last ip that 'ping' got.   So, if a host has a power of 2 number of ips,
rotation is broken.. particularly badly if there are only two ips total.

note: nscd is not running, and it does not appear to fix the problem

test program:

int main(void)
    struct addrinfo *result;
    struct addrinfo *res;
    int error;

   /* nautilus has two hosts, we want to pick a random
     * one.  
     * Note: problem occurs with or without final trailing '.' */
    error = getaddrinfo("",
            NULL, NULL, &result);
    // sent two DNS queries, which breaks rotation of two ips
    // first ip result is always the same ip, even though nameserver is
reordering each response

strace of c program:

strace -s 100 -e sendto ./a.out 
sendto(3, "\24\0\0\0\26\0\1\3\276\301pO\0\0\0\0\0\0\0\0", 20, 0,
{sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
49, MSG_NOSIGNAL, NULL, 0) = 49
49, MSG_NOSIGNAL, NULL, 0) = 49

Configure bugmail:
------- You are receiving this mail because: -------
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]