diff --git a/snail-job-client/snail-job-client-common/src/main/java/com/aizuda/snailjob/client/common/rpc/client/RpcClientInvokeHandler.java b/snail-job-client/snail-job-client-common/src/main/java/com/aizuda/snailjob/client/common/rpc/client/RpcClientInvokeHandler.java index 201c3ac39..e71c2b17b 100644 --- a/snail-job-client/snail-job-client-common/src/main/java/com/aizuda/snailjob/client/common/rpc/client/RpcClientInvokeHandler.java +++ b/snail-job-client/snail-job-client-common/src/main/java/com/aizuda/snailjob/client/common/rpc/client/RpcClientInvokeHandler.java @@ -6,6 +6,7 @@ import com.aizuda.snailjob.client.common.annotation.Mapping; import com.aizuda.snailjob.client.common.exception.SnailJobClientException; import com.aizuda.snailjob.client.common.exception.SnailJobClientTimeOutException; import com.aizuda.snailjob.common.core.enums.StatusEnum; +import com.aizuda.snailjob.common.core.exception.SnailJobRemotingTimeOutException; import com.aizuda.snailjob.common.core.model.NettyResult; import com.aizuda.snailjob.common.core.model.Result; import com.aizuda.snailjob.common.core.rpc.RpcContext; @@ -44,7 +45,7 @@ public class RpcClientInvokeHandler> implements Invocat } @Override - public R invoke(final Object proxy, final Method method, final Object[] args) throws InterruptedException { + public R invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { StopWatch sw = new StopWatch(); Mapping annotation = method.getAnnotation(Mapping.class); SnailJobRequest snailJobRequest = new SnailJobRequest(args); @@ -78,7 +79,7 @@ public class RpcClientInvokeHandler> implements Invocat try { return newFuture.get(Integer.MAX_VALUE, TimeUnit.MILLISECONDS); } catch (ExecutionException e) { - throw new SnailJobClientException("Request to remote interface exception. path:[{}]", annotation.path()); + throw e.getCause(); } catch (TimeoutException e) { throw new SnailJobClientTimeOutException("Request to remote interface timed out. path:[{}]", annotation.path()); } diff --git a/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/rpc/client/RpcClientInvokeHandler.java b/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/rpc/client/RpcClientInvokeHandler.java index edaad573f..c9f77b75c 100644 --- a/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/rpc/client/RpcClientInvokeHandler.java +++ b/snail-job-server/snail-job-server-common/src/main/java/com/aizuda/snailjob/server/common/rpc/client/RpcClientInvokeHandler.java @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Assert; import com.aizuda.snailjob.common.core.constant.SystemConstants; import com.aizuda.snailjob.common.core.context.SpringContext; import com.aizuda.snailjob.common.core.enums.StatusEnum; +import com.aizuda.snailjob.common.core.exception.SnailJobRemotingTimeOutException; import com.aizuda.snailjob.common.core.model.NettyResult; import com.aizuda.snailjob.common.core.model.SnailJobRequest; import com.aizuda.snailjob.common.core.model.Result; @@ -171,15 +172,7 @@ public class RpcClientInvokeHandler implements InvocationHandler { return null; } else { Assert.notNull(newFuture, () -> new SnailJobServerException("completableFuture is null")); - try { - return (Result) newFuture.get(Integer.MAX_VALUE, TimeUnit.MILLISECONDS); - } catch (ExecutionException e) { - throw new SnailJobServerException("Request to remote interface exception. path:[{}]", - mapping.path()); - } catch (TimeoutException e) { - throw new SnailJobServerException("Request to remote interface timed out. path:[{}]", - mapping.path()); - } + return (Result) newFuture.get(Integer.MAX_VALUE, TimeUnit.MILLISECONDS); } }); @@ -189,9 +182,9 @@ public class RpcClientInvokeHandler implements InvocationHandler { hostIp, hostPort, NetUtil.getLocalIpStr()); return result; - } catch (RestClientException ex) { - // 网络异常 - if (ex instanceof ResourceAccessException && failover) { + } catch (ExecutionException ex) { + // 网络异常 TimeoutException | + if (ex.getCause() instanceof SnailJobRemotingTimeOutException && failover) { log.error("request client I/O error, count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId, hostIp, hostPort, NetUtil.getLocalIpStr(), ex); @@ -204,7 +197,7 @@ public class RpcClientInvokeHandler implements InvocationHandler { routeKey); // 这里表示无可用节点 if (Objects.isNull(serverNode)) { - throw ex; + throw ex.getCause(); } this.hostId = serverNode.getHostId(); @@ -215,7 +208,7 @@ public class RpcClientInvokeHandler implements InvocationHandler { // 其他异常继续抛出 log.error("request client error.count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", count, hostId, hostIp, hostPort, NetUtil.getLocalIpStr(), ex); - throw ex; + throw ex.getCause(); } } catch (Exception ex) { log.error("request client unknown exception. count:[{}] clientId:[{}] clientAddr:[{}:{}] serverIp:[{}]", @@ -225,7 +218,7 @@ public class RpcClientInvokeHandler implements InvocationHandler { if (ex.getClass().isAssignableFrom(RetryException.class)) { RetryException re = (RetryException) ex; throwable = re.getLastFailedAttempt().getExceptionCause(); - if (throwable instanceof ResourceAccessException) { + if (throwable.getCause() instanceof SnailJobRemotingTimeOutException) { // 若重试之后该接口仍然有问题,进行路由剔除处理 CacheRegisterTable.remove(groupName, namespaceId, hostId); }