diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java index e3b90da794ba..3bf71829fed0 100644 --- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java +++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hdds; +import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.ServiceException; import jakarta.annotation.Nonnull; @@ -685,21 +686,26 @@ public static int roundupMb(long bytes) { * or a RpcException. */ public static Throwable getUnwrappedException(Exception ex) { + Throwable t = ex; if (ex instanceof ServiceException) { - Throwable t = ex.getCause(); - if (t instanceof RemoteException) { - t = ((RemoteException) t).unwrapRemoteException(); - } - while (t != null) { - if (t instanceof RpcException || - t instanceof AccessControlException || - t instanceof SecretManager.InvalidToken) { - return t; - } - t = t.getCause(); + t = ex.getCause(); + } + if (t instanceof RemoteException) { + t = ((RemoteException) t).unwrapRemoteException(); + } + while (t != null) { + if (t instanceof RpcException || + t instanceof AccessControlException || + t instanceof SecretManager.InvalidToken) { + break; + } + Throwable cause = t.getCause(); + if (cause == null || cause instanceof RemoteException) { + break; } + t = cause; } - return null; + return t; } /** @@ -719,7 +725,7 @@ public static boolean shouldNotFailoverOnRpcException(Throwable exception) { return true; } } - return false; + return exception instanceof InvalidProtocolBufferException; } /**