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 2022/10/03 13:30:58 UTC

[httpcomponents-client] branch master updated: HTTPCLIENT-2236: MultihomeIOSessionRequester fails to enhance the cause exception in case of connect failure if the remoteAddress argument has been given

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ab435c27 HTTPCLIENT-2236: MultihomeIOSessionRequester fails to enhance the cause exception in case of connect failure if the remoteAddress argument has been given
7ab435c27 is described below

commit 7ab435c271b6ff3bde4e737c2b02ba873ffa8b55
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Fri Sep 30 16:34:51 2022 +0200

    HTTPCLIENT-2236: MultihomeIOSessionRequester fails to enhance the cause exception in case of connect failure if the remoteAddress argument has been given
---
 .../http/impl/nio/MultihomeIOSessionRequester.java | 33 ++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

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 bb4264b70..8ae8d14fc 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
@@ -66,19 +66,48 @@ final class MultihomeIOSessionRequester {
             final Object attachment,
             final FutureCallback<IOSession> callback) {
 
+        final ComplexFuture<IOSession> future = new ComplexFuture<>(callback);
         if (remoteAddress != null) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("{}:{} connecting {} to {} ({})",
                         remoteEndpoint.getHostName(), remoteEndpoint.getPort(), localAddress, remoteAddress, connectTimeout);
             }
-            return connectionInitiator.connect(remoteEndpoint, remoteAddress, localAddress, connectTimeout, attachment, callback);
+            final Future<IOSession> sessionFuture = connectionInitiator.connect(remoteEndpoint, remoteAddress, localAddress, connectTimeout, attachment, new FutureCallback<IOSession>() {
+                @Override
+                public void completed(final IOSession session) {
+                    future.completed(session);
+                }
+
+                @Override
+                public void failed(final Exception cause) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("{}:{} connection to {} failed ({}); terminating operation",
+                                remoteEndpoint.getHostName(), remoteEndpoint.getPort(), remoteAddress, cause.getClass());
+                    }
+                    if (cause instanceof IOException) {
+                        future.failed(ConnectExceptionSupport.enhance((IOException) cause, remoteEndpoint,
+                                (remoteAddress instanceof InetSocketAddress) ?
+                                        new InetAddress[] { ((InetSocketAddress) remoteAddress).getAddress() } :
+                                        new InetAddress[] {}));
+                    } else {
+                        future.failed(cause);
+                    }
+                }
+
+                @Override
+                public void cancelled() {
+                    future.cancel();
+                }
+
+            });
+            future.setDependency(sessionFuture);
+            return future;
         }
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("{} resolving remote address", remoteEndpoint.getHostName());
         }
 
-        final ComplexFuture<IOSession> future = new ComplexFuture<>(callback);
         final InetAddress[] remoteAddresses;
         try {
             remoteAddresses = dnsResolver.resolve(remoteEndpoint.getHostName());