Sources Bugzilla – Bug 3675
libc caches resolv.conf forever
Last modified: 2006-12-07 15:22:18 UTC
Relevant libc extension: BIND-8.2.3-T5B
libc apparently reads /etc/resolv.conf upon the first access to getaddrinfo()
and parses it and continues with the parsed results forever, even if
/etc/resolv.conf changes. There is no documented interface to cause libc to
re-read the resolv.conf file.
Real-world problem: Processes designed to run for many days will not detect
resolv.conf changes. On systems without permanent internet connection,
resolv.conf may be rewritten by unrelated DHCP client or PPP peer software after
an application using getaddrinfo() has started. The result is that errors such
as EAI_AGAIN that stem from stale /etc/resolv.conf parsed at application
start-up time persist until the application terminates.
Suggested solution: be sure to check /etc/resolv.conf for changes and, when
changes are detected, re-parse it every few (say, 5) seconds, or when EAI_AGAIN
would be returned. The time limit should bound the amount of time spent parsing
said fail without introducing too much delay WRT picking up changes.
Checking for resolv.conf changes upon EAI_AGAIN is clearly my favorite.
That's what res_init() is for, call it.
Thank you. Could you confirm that res_init() does:
- *not* look at the RES_INIT state (i. e. re-reads resolv.conf every time it is
- *not* leak memory when called frequently?