Skip to content

Commit

Permalink
HTTPCLIENT-2314: Handle gracefully a failure of DnsResolver to return…
Browse files Browse the repository at this point in the history
… a list of resolved addresses (#533)
  • Loading branch information
phax committed Jan 7, 2024
1 parent 67519a1 commit 1650831
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public InetAddress[] resolve(final String host) throws UnknownHostException {
LOG.info("Resolving {} to {}", host, Arrays.deepToString(resolvedAddresses));
}
if(resolvedAddresses == null){
throw new UnknownHostException(host + " cannot be resolved");
throw new UnknownHostException(host);
}
return resolvedAddresses;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -143,8 +144,12 @@ public void connect(
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public void cancelled() {
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;
Expand Down

0 comments on commit 1650831

Please sign in to comment.