Improve Java's handling of EAGAIN with respect to DNS lookups
Observed on Linux, but probably applicable to all platforms
FULL JDK VERSION
Occasionally, the system call getaddrinfo() fails with a return value EAI_SYSTEM and errno set to EAGAIN, meaning that the resource is temporarily unavailable. Under these circumstances Java throws an UnknownHostException, which can cause confusion for application users. We believe that Java's handing of this error needs to be improved.
We experimented with a standalone C program and found that the failure is highly transient - calling getaddrinfo() again after 50ms almost always succeeds.
The JRE's handling of this scenario could therefore be improved. Here are two suggestions:
1. Implement a retry when confronted with an EAGAIN error from the
2. Redesign the Java API to distinguish between true lookup failures and
EAGAIN failures, via the introduction of a new Exception class, to
allow applications to handle the different error scenarios.
The application could catch all UnknownHostExceptions and retry just in case the error was an EAGAIN, but this is obviously far from ideal.