sustrik / dsock

An obsolete project
Other
82 stars 23 forks source link

DNS Resolver crashes after repeated name resolution #19

Closed vlm closed 6 years ago

vlm commented 8 years ago

To reproduce in the current master:

> make ./tests/dns  && ./tests/dns 
make: `tests/dns' is up to date.
Assert failed: resolver (ipaddr.c:258)
Abort trap: 6
> cat tests/dns.c 
#include <assert.h>

#include "../dsock.h"

int main() {

    /* Crash test for remote DNS resolution */
    for(int n = 0; n < 1000; n++) {
        ipaddr addr;
        (void)ipaddr_remote(&addr, "example.org", 80, IPADDR_IPV4, now() + 10);
    }

    return 0;
}

P.S. Mac OS X 10.12, XCode 8.0 (clang-800.0.38).

sustrik commented 8 years ago

Hm. It's not happening on LInux. Can you run it under debugger and check what the value of "rc" is when the assert happens?

vlm commented 8 years ago

Turns out, the case is easier than I thought.

rc = 24, errno: 24 Too many open files

By default, macOS's limit is 256, hence an earlier error.

However, it shouldn't crash because of that.

sustrik commented 8 years ago

Even so, the DNS queries are done one after another, not simultaneously. There should be one fd used. It looks like there's some kind of a leak there.

Running the test under valgrind:

==11105== 64,000 bytes in 1,000 blocks are definitely lost in loss record 6 of 7
==11105==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11105==    by 0x41452C: dns_ai_setent (dns.c:7457)
==11105==    by 0x414BF2: dns_ai_nextent (dns.c:7577)
==11105==    by 0x402536: ipaddr_remote (ipaddr.c:273)
==11105==    by 0x4018B4: main (test.c:34)
sustrik commented 6 years ago

This was moved to libdill in the meantime and the leak was fixed.