4

Executive Summary

  • Does Java query the next resolv.conf name server entry if the first one fails or times out?
  • What is the default timeout at which Java will consider a resolver "down"?

Details

In /etc/resolv.conf, in most sites, there are multiple DNS servers configured for use by the system. Can anyone clarify what happens, with Java, if the first DNS server in the list fails? For example, imagine the following resolv.conf:

nameserver 8.8.8.8
nameserver 4.4.4.4

If 8.8.8.8 becomes unreachable then will Java try 4.4.4.4? In our experience it does not - we saw many threads waiting to resolve DNS names even though the backup DNS servers were reachable.

  • 1
    Just an aside I don't know if you are using the google dns or that's just part of your example IP e.g. 8.8.8.8 or not but 8.8.4.4 is the other google DNS IP not 4.4.4.4 – davey Feb 25 '14 at 10:19
  • Have you ever found a resolution for this issue? We're having the same problem with a java based application (BladeLogic Server Automation) and we haven't found a solution yet. – Yanick Girouard Jul 11 '14 at 19:14
  • Have you tried the /etc/resolv.conf timeout value specified below? – Fred Clausen Jul 14 '14 at 5:15
3

On Linux java will delegate hostname resolution to the underlying C system library which does the actual resolving.

The name servers will be queried in the order listed as specified in /etc/resolv.conf after the other sources of information specified in /etc/nsswitch.conf have been queried (think /etc/hosts but possibly NIS or LDAP).

You can specify a timeout value in /etc/resolv.conf , according to the man page the default is 5 seconds.

If your first server gives a valid error code I.e. servfail the second name server will not be queried

  • Why won't the second server be queried if the first one returns a valid error? Do you know if there's any way to change that behavior? – Naliba Jun 17 '16 at 16:45
2

As a program (any process, JVM included) has its very first DNS request it reads and caches forever the entire contents of /etc/resolv.conf by default. It never refreshes that info later, even when it encounters a total DNS failure. The program would need to have some specific system calls programmed to behave in more user-friendly manner. This SO question explains the details.

I suspect that you edited /etc/resolv.conf while the JVM was running. Restart it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.