You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2024/01/07 14:44:45 UTC
(httpcomponents-client) branch 5.3.x updated: HTTPCLIENT-2314: Handle gracefully a failure of DnsResolver to return a list of resolved addresses (#533)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch 5.3.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
The following commit(s) were added to refs/heads/5.3.x by this push:
new 16508314d HTTPCLIENT-2314: Handle gracefully a failure of DnsResolver to return a list of resolved addresses (#533)
16508314d is described below
commit 16508314d1aefc3b1b978125da9855998d6c2921
Author: Philip Helger <ph...@helger.com>
AuthorDate: Sun Jan 7 15:44:40 2024 +0100
HTTPCLIENT-2314: Handle gracefully a failure of DnsResolver to return a list of resolved addresses (#533)
---
.../java/org/apache/hc/client5/http/impl/InMemoryDnsResolver.java | 2 +-
.../client5/http/impl/io/DefaultHttpClientConnectionOperator.java | 7 ++++++-
.../hc/client5/http/impl/nio/MultihomeIOSessionRequester.java | 3 +++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/InMemoryDnsResolver.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/InMemoryDnsResolver.java
index 3894a6ca7..040f9ca4e 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/InMemoryDnsResolver.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/InMemoryDnsResolver.java
@@ -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;
}
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
index 5507d4015..bbbf826e1 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
@@ -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();
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java
index 8ae8d14fc..ac586428a 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/MultihomeIOSessionRequester.java
@@ -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;