Copilot commented on code in PR #18299:
URL: https://github.com/apache/iotdb/pull/18299#discussion_r3644552215


##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/request/AsyncRequestManager.java:
##########
@@ -210,6 +210,13 @@ protected void sendAsyncRequest(
           endPoint,
           e.getMessage(),
           retryCount);
+      try {
+        onRequestFailure(e, endPoint);
+      } catch (final RuntimeException reportingFailure) {
+        if (reportingFailure != e) {
+          e.addSuppressed(reportingFailure);
+        }
+      }

Review Comment:
   If `onRequestFailure(...)` throws, the code adds it via 
`e.addSuppressed(...)` to preserve the original failure. However, 
`addSuppressed` can throw (e.g., when suppression is disabled) and would then 
replace the original request failure. Wrap the suppression attempt so reporting 
failures never escape.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/client/sync/SyncThriftClientWithErrorHandler.java:
##########
@@ -54,6 +87,13 @@ public Object intercept(Object o, Method method, Object[] 
objects, MethodProxy m
     try {
       return methodProxy.invokeSuper(o, objects);
     } catch (Throwable t) {
+      try {
+        failureHandler.accept(t, (ThriftClient) o);
+      } catch (final RuntimeException reportingFailure) {
+        if (reportingFailure != t) {
+          t.addSuppressed(reportingFailure);
+        }
+      }

Review Comment:
   If the failure-reporting hook throws, the code adds it as a suppressed 
exception. `addSuppressed(...)` itself can throw (e.g., if suppression is 
disabled), which would let the reporting failure replace the original transport 
failure. Wrap the suppression attempt to fully isolate hook failures.



##########
external-service-impl/rest/src/main/java/org/apache/iotdb/rest/TrustedChannelAuditHandshakeListener.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.rest;
+
+import org.apache.iotdb.common.rpc.thrift.TEndPoint;
+import org.apache.iotdb.commons.audit.TrustedChannelFailureHandler;
+
+import org.eclipse.jetty.io.EndPoint;
+import org.eclipse.jetty.io.ssl.SslHandshakeListener;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.Objects;
+
+final class TrustedChannelAuditHandshakeListener implements 
SslHandshakeListener {
+
+  private final TrustedChannelFailureHandler failureHandler;
+
+  TrustedChannelAuditHandshakeListener(TrustedChannelFailureHandler 
failureHandler) {
+    this.failureHandler = Objects.requireNonNull(failureHandler);
+  }
+
+  @Override
+  public void handshakeFailed(Event event, Throwable failure) {
+    recordHandshakeFailure(event.getEndPoint(), failure);
+  }
+
+  void recordHandshakeFailure(EndPoint endPoint, Throwable failure) {
+    if (endPoint == null) {
+      return;
+    }
+
+    TEndPoint initiator = toEndPoint(endPoint.getRemoteSocketAddress());
+    TEndPoint target = toEndPoint(endPoint.getLocalSocketAddress());
+    if (initiator == null || target == null) {
+      return;
+    }
+
+    try {
+      failureHandler.onFailure(failure, initiator, target);
+    } catch (RuntimeException auditFailure) {
+      if (auditFailure != failure) {
+        failure.addSuppressed(auditFailure);
+      }
+    }
+  }

Review Comment:
   In the reporting-failure path, `Throwable.addSuppressed(...)` can throw 
(e.g., when suppressed exceptions are disabled), which would cause the audit 
hook failure to replace the original handshake failure. Also guard against a 
null `failure` to avoid NPE in the suppression path.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/consensus/iotv2/container/IoTV2GlobalComponentContainer.java:
##########
@@ -87,6 +92,26 @@ public ScheduledExecutorService getBackgroundTaskService() {
     return this.backgroundTaskService;
   }
 
+  public void configureTrustedChannelFailureHandler(
+      final TEndPoint thisNode, final TrustedChannelFailureHandler 
trustedChannelFailureHandler) {
+    this.thisNode = Objects.requireNonNull(thisNode);
+    this.trustedChannelFailureHandler = 
Objects.requireNonNull(trustedChannelFailureHandler);
+  }
+
+  public void reportTrustedChannelFailure(final Throwable failure, final 
TEndPoint targetEndPoint) {
+    final TEndPoint initiatorEndPoint = thisNode;
+    if (failure == null || initiatorEndPoint == null || targetEndPoint == 
null) {
+      return;
+    }
+    try {
+      trustedChannelFailureHandler.onFailure(failure, initiatorEndPoint, 
targetEndPoint);
+    } catch (final RuntimeException reportingFailure) {
+      if (reportingFailure != failure) {
+        failure.addSuppressed(reportingFailure);
+      }
+    }

Review Comment:
   `failure.addSuppressed(reportingFailure)` can throw (notably 
`IllegalStateException` when suppression is disabled), which would undermine 
the goal of ensuring reporting-hook failures don't replace the original 
failure. Wrap the suppression attempt so this method never throws due to 
reporting.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/sink/client/IoTDBSyncClientManager.java:
##########
@@ -299,6 +304,22 @@ public void sendHandshakeReq(final Pair<IoTDBSyncClient, 
Boolean> clientAndStatu
     }
   }
 
+  private void notifyClientConnectionFailure(
+      final Exception failure, final TEndPoint targetEndPoint) {
+    try {
+      onClientConnectionFailure(failure, targetEndPoint);
+    } catch (final RuntimeException reportingFailure) {
+      if (reportingFailure != failure) {
+        failure.addSuppressed(reportingFailure);
+      }
+    }

Review Comment:
   If `onClientConnectionFailure(...)` throws, the code adds it as a suppressed 
exception to preserve the original connection failure. `addSuppressed(...)` can 
throw (e.g., if suppression is disabled), which would let reporting failures 
escape and potentially replace the original failure. Wrap the suppression 
attempt.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to