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

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


The following commit(s) were added to refs/heads/master by this push:
     new e7fb8c38fe5 No need to retry when meets SSL Handshake error between DN 
and CN (#16513)
e7fb8c38fe5 is described below

commit e7fb8c38fe5ee8afb4d9825dcfc9cdffffd62cba
Author: Haonan <[email protected]>
AuthorDate: Mon Sep 29 14:21:02 2025 +0800

    No need to retry when meets SSL Handshake error between DN and CN (#16513)
---
 .../iotdb/db/protocol/client/ConfigNodeClient.java | 56 +++++++++++++---------
 .../java/org/apache/iotdb/db/service/DataNode.java | 10 ++++
 2 files changed, 43 insertions(+), 23 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
index 4f6548ef112..6ce425143f2 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/client/ConfigNodeClient.java
@@ -200,10 +200,12 @@ import org.apache.commons.pool2.PooledObject;
 import org.apache.commons.pool2.impl.DefaultPooledObject;
 import org.apache.thrift.TException;
 import org.apache.thrift.transport.TTransport;
-import org.apache.thrift.transport.TTransportException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.net.ssl.SSLHandshakeException;
+
+import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
@@ -269,27 +271,23 @@ public class ConfigNodeClient implements 
IConfigNodeRPCService.Iface, ThriftClie
   }
 
   public void connect(TEndPoint endpoint, int timeoutMs) throws TException {
-    try {
-      transport =
-          commonConfig.isEnableInternalSSL()
-              ? DeepCopyRpcTransportFactory.INSTANCE.getTransport(
-                  endpoint.getIp(),
-                  endpoint.getPort(),
-                  timeoutMs,
-                  commonConfig.getTrustStorePath(),
-                  commonConfig.getTrustStorePwd(),
-                  commonConfig.getKeyStorePath(),
-                  commonConfig.getKeyStorePwd())
-              : DeepCopyRpcTransportFactory.INSTANCE.getTransport(
-                  // As there is a try-catch already, we do not need to use 
TSocket.wrap
-                  endpoint.getIp(), endpoint.getPort(), timeoutMs);
-      if (!transport.isOpen()) {
-        transport.open();
-      }
-      configNode = endpoint;
-    } catch (TTransportException e) {
-      throw new TException(e);
+    transport =
+        commonConfig.isEnableInternalSSL()
+            ? DeepCopyRpcTransportFactory.INSTANCE.getTransport(
+                endpoint.getIp(),
+                endpoint.getPort(),
+                timeoutMs,
+                commonConfig.getTrustStorePath(),
+                commonConfig.getTrustStorePwd(),
+                commonConfig.getKeyStorePath(),
+                commonConfig.getKeyStorePwd())
+            : DeepCopyRpcTransportFactory.INSTANCE.getTransport(
+                // As there is a try-catch already, we do not need to use 
TSocket.wrap
+                endpoint.getIp(), endpoint.getPort(), timeoutMs);
+    if (!transport.isOpen()) {
+      transport.open();
     }
+    configNode = endpoint;
 
     client = new 
IConfigNodeRPCService.Client(property.getProtocolFactory().getProtocol(transport));
   }
@@ -315,13 +313,15 @@ public class ConfigNodeClient implements 
IConfigNodeRPCService.Iface, ThriftClie
   }
 
   private void tryToConnect(int timeoutMs) throws TException {
+    TException exception = null;
     if (configLeader != null) {
       try {
         connect(configLeader, timeoutMs);
         return;
-      } catch (TException ignore) {
+      } catch (TException e) {
         logger.warn("The current node leader may have been down {}, try next 
node", configLeader);
         configLeader = null;
+        exception = e;
       }
     } else {
       try {
@@ -344,10 +344,17 @@ public class ConfigNodeClient implements 
IConfigNodeRPCService.Iface, ThriftClie
       try {
         connect(tryEndpoint, timeoutMs);
         return;
-      } catch (TException ignore) {
+      } catch (TException e) {
         logger.warn("The current node may have been down {},try next node", 
tryEndpoint);
+        exception = e;
       }
     }
+    if (exception != null
+        && exception.getCause() != null
+        && exception.getCause().getCause() != null
+        && exception.getCause().getCause() instanceof IOException) {
+      throw new TException(exception.getCause().getCause());
+    }
 
     throw new TException(MSG_RECONNECTION_FAIL);
   }
@@ -433,6 +440,9 @@ public class ConfigNodeClient implements 
IConfigNodeRPCService.Iface, ThriftClie
                 Thread.currentThread().getStackTrace()[2].getMethodName());
         logger.warn(message, e);
         configLeader = null;
+        if (e.getCause() != null && e.getCause() instanceof 
SSLHandshakeException) {
+          throw e;
+        }
       }
 
       // If we have detected all configNodes and still not return
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
index ef44672bbb4..cebf7dab9f3 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/service/DataNode.java
@@ -127,6 +127,8 @@ import org.apache.tsfile.utils.ReadWriteIOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.net.ssl.SSLHandshakeException;
+
 import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -374,6 +376,14 @@ public class DataNode extends ServerCommandLine implements 
DataNodeMBean {
         break;
       } catch (TException | ClientManagerException e) {
         logger.warn("Cannot pull system configurations from 
ConfigNode-leader", e);
+        if (e.getCause() != null && e.getCause().getCause() != null) {
+          Throwable cause = e.getCause().getCause();
+          if (cause instanceof SSLHandshakeException) {
+            throw new StartupException("Cannot SSL Handshake with 
ConfigNode-leader.");
+          } else if (cause.getMessage() != null && 
cause.getMessage().contains("IOException")) {
+            throw new StartupException("Cannot connect to ConfigNode-leader.");
+          }
+        }
         retry--;
       }
 

Reply via email to