[uClibc] Re: gethostbyaddr long delay for unresolvable addresses

Jeff Gray jeffg at magtech.com.au
Tue Aug 19 00:58:02 UTC 2003


Derek Ross wrote:

> I was looking though uclibc archives and I discovered that you have 
> the same problem I'm having.  Unfortunately, it appears that nobody 
> has answered your question.
>
> Have you made any discoveries about the cause of this problem?  I 
> would be interested in knowing if there's a solution of some sort (if 
> you're not busy of course).

I think it came from uclibc not timing out of unresolved addresses in 
the same way that glibc does. My solution was to change the number of 
times it retries reverse lookups.

Look in the file /uclibc-source/libc/inet/resolve.c
The function gethostbyaddr_r() implements this call. In the middle of 
this function is a big loop, which iterates around a number of times, 
calling __dns_lookup(). This function has a loop of up to MAX_RETRIES 
times, which calls select() with REPLY_TIMEOUT as a parameter.

These 2 constants are they key to limiting the amount of time spent 
trying to do the lookup. They are both defined at the top of resolve.c. 
I have changed MAX_RETRIES to 1 (instead of 15) and REPLY_TIMEOUT to 2 
(instead of 10). You may find less strict times may be more appropriate 
for you but this fixed the problem very effectively for me.

I assume the problem relates to dns_lookup deciding that the lookup has 
failed, rather than not received a response. Once it fails, it should 
not try again. But I haven't analysed this function to understand its 
workings well enough to be sure.

Hope this helps.
Jeff




More information about the uClibc mailing list