You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by am...@apache.org on 2023/06/14 10:56:34 UTC

[knox] branch master updated: KNOX-2912 - Don't fail over non idempotent requests unless it's a connect exception - ConnectionTimeout (#763)

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

amagyar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 017242ac7 KNOX-2912 - Don't fail over non idempotent requests unless it's a connect exception - ConnectionTimeout (#763)
017242ac7 is described below

commit 017242ac73724b930102a82fd1449f4e56d7b84f
Author: Attila Magyar <m....@gmail.com>
AuthorDate: Wed Jun 14 12:56:29 2023 +0200

    KNOX-2912 - Don't fail over non idempotent requests unless it's a connect exception - ConnectionTimeout (#763)
---
 .../apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java   | 2 +-
 .../apache/knox/gateway/ha/dispatch/i18n/HaDispatchMessages.java  | 2 +-
 .../apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java | 2 +-
 gateway-util-common/pom.xml                                       | 5 ++++-
 .../src/main/java/org/apache/knox/gateway/util/HttpUtils.java     | 8 ++++++--
 .../src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java | 1 +
 6 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
index 8d5f5b859..0f2bb23cb 100644
--- a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
+++ b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/ConfigurableHADispatch.java
@@ -220,7 +220,7 @@ public class ConfigurableHADispatch extends ConfigurableDispatch {
     } catch ( IOException e ) {
       /* if non-idempotent requests are not allowed to failover, unless it's a connection error */
       if(!isConnectionError(e.getCause()) && isNonIdempotentAndNonIdempotentFailoverDisabled(outboundRequest)) {
-        LOG.cannotFailoverNonIdempotentRequest(outboundRequest.getMethod(), e.toString());
+        LOG.cannotFailoverNonIdempotentRequest(outboundRequest.getMethod(), e.getCause());
         /* mark endpoint as failed */
         markEndpointFailed(outboundRequest, inboundRequest);
         throw e;
diff --git a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/i18n/HaDispatchMessages.java b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/i18n/HaDispatchMessages.java
index 901d87bc6..c3a855c6d 100644
--- a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/i18n/HaDispatchMessages.java
+++ b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/dispatch/i18n/HaDispatchMessages.java
@@ -55,5 +55,5 @@ public interface HaDispatchMessages {
   void unsupportedEncodingException(String cause);
 
   @Message(level = MessageLevel.ERROR, text = "Request is non-idempotent {0}, failover prevented, to allow non-idempotent requests to failover set 'failoverNonIdempotentRequestEnabled=true' in HA config. Non connection related error: {1}")
-  void cannotFailoverNonIdempotentRequest(String method, String cause);
+  void cannotFailoverNonIdempotentRequest(String method, Throwable cause);
 }
diff --git a/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java b/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java
index 0c7865c14..b284ed4cd 100644
--- a/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java
+++ b/gateway-service-webhdfs/src/main/java/org/apache/knox/gateway/hdfs/dispatch/AbstractHdfsHaDispatch.java
@@ -62,7 +62,7 @@ public abstract class AbstractHdfsHaDispatch extends ConfigurableHADispatch {
       } catch (StandbyException | SafeModeException | IOException e) {
         /* if non-idempotent requests are not allowed to failover */
         if(!failoverNonIdempotentRequestEnabled && nonIdempotentRequests.stream().anyMatch(outboundRequest.getMethod()::equalsIgnoreCase)) {
-          LOG.cannotFailoverNonIdempotentRequest(outboundRequest.getMethod(), e.toString());
+          LOG.cannotFailoverNonIdempotentRequest(outboundRequest.getMethod(), e.getCause());
           throw e;
         } else {
           printExceptionLogMessage(e, outboundRequest.getURI().toString());
diff --git a/gateway-util-common/pom.xml b/gateway-util-common/pom.xml
index fe4406034..104e87b82 100644
--- a/gateway-util-common/pom.xml
+++ b/gateway-util-common/pom.xml
@@ -81,7 +81,10 @@
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-slf4j-impl</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
         <!-- ********** ********** ********** ********** ********** ********** -->
         <!-- ********** Test Dependencies                           ********** -->
         <!-- ********** ********** ********** ********** ********** ********** -->
diff --git a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
index 46d36f599..088bafb5f 100644
--- a/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
+++ b/gateway-util-common/src/main/java/org/apache/knox/gateway/util/HttpUtils.java
@@ -34,8 +34,12 @@ import java.util.Map;
 import java.util.StringTokenizer;
 
 public class HttpUtils {
-  private static final List<Class<? extends IOException>> connectionErrors = asList(UnknownHostException.class, NoRouteToHostException.class,
-          SocketException.class);
+  private static final List<Class<? extends IOException>> connectionErrors = asList(
+          UnknownHostException.class,
+          NoRouteToHostException.class,
+          SocketException.class,
+          org.apache.http.conn.ConnectTimeoutException.class
+  );
 
   public static Map<String, List<String>> splitQuery(String queryString)
       throws UnsupportedEncodingException {
diff --git a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
index 7a7309519..94f9448c4 100644
--- a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
+++ b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/HttpUtilsTest.java
@@ -227,5 +227,6 @@ public class HttpUtilsTest {
     assertThat(isConnectionError(new PortUnreachableException()), is(true));
     assertThat(isConnectionError(new IOException()), is(false));
     assertThat(isConnectionError(new RuntimeException()), is(false));
+    assertThat(isConnectionError(new org.apache.http.conn.ConnectTimeoutException()), is(true));
   }
 }