HTTPCLIENT-2314: Handle gracefully a failure of DnsResolver to return a list of resolved addresses (#533)
This commit is contained in:
parent
aad5987246
commit
8228ddf28a
|
@ -90,7 +90,7 @@ public class InMemoryDnsResolver implements DnsResolver {
|
|||
LOG.info("Resolving {} to {}", host, Arrays.deepToString(resolvedAddresses));
|
||||
}
|
||||
if(resolvedAddresses == null){
|
||||
throw new UnknownHostException(host + " cannot be resolved");
|
||||
throw new UnknownHostException(host);
|
||||
}
|
||||
return resolvedAddresses;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.net.InetSocketAddress;
|
|||
import java.net.Proxy;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.hc.client5.http.ConnectExceptionSupport;
|
||||
|
@ -143,8 +144,12 @@ public class DefaultHttpClientConnectionOperator implements HttpClientConnection
|
|||
remoteAddresses = this.dnsResolver.resolve(host.getHostName());
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("{} resolved to {}", host.getHostName(), Arrays.asList(remoteAddresses));
|
||||
LOG.debug("{} resolved to {}", host.getHostName(), remoteAddresses == null ? "null" : Arrays.asList(remoteAddresses));
|
||||
}
|
||||
|
||||
if (remoteAddresses == null || remoteAddresses.length == 0) {
|
||||
throw new UnknownHostException(host.getHostName());
|
||||
}
|
||||
}
|
||||
|
||||
final Timeout soTimeout = socketConfig.getSoTimeout();
|
||||
|
|
|
@ -111,6 +111,9 @@ final class MultihomeIOSessionRequester {
|
|||
final InetAddress[] remoteAddresses;
|
||||
try {
|
||||
remoteAddresses = dnsResolver.resolve(remoteEndpoint.getHostName());
|
||||
if (remoteAddresses == null || remoteAddresses.length == 0) {
|
||||
throw new UnknownHostException(remoteEndpoint.getHostName());
|
||||
}
|
||||
} catch (final UnknownHostException ex) {
|
||||
future.failed(ex);
|
||||
return future;
|
||||
|
|
Loading…
Reference in New Issue