[
https://issues.apache.org/jira/browse/SCB-1012?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16677747#comment-16677747
]
ASF GitHub Bot commented on SCB-1012:
-------------------------------------
liubao68 closed pull request #984: [SCB-1012] add NoRouteToHostException in
retry's exception
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/984
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/DefaultRetryExtensionsFactory.java
b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/DefaultRetryExtensionsFactory.java
index 7176d7af5..f8ab374ab 100644
---
a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/DefaultRetryExtensionsFactory.java
+++
b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/DefaultRetryExtensionsFactory.java
@@ -18,7 +18,9 @@
import java.io.IOException;
import java.net.ConnectException;
+import java.net.NoRouteToHostException;
import java.net.SocketTimeoutException;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -44,6 +46,18 @@
private static final Collection<String> ACCEPT_VALUES = Lists.newArrayList(
RETRY_DEFAULT);
+ private static final Map<Class<? extends Throwable>, List<String>>
strictRetriable =
+ ImmutableMap.<Class<? extends Throwable>, List<String>>builder()
+ .put(ConnectException.class, Arrays.asList())
+ .put(SocketTimeoutException.class, Arrays.asList())
+ /*
+ * deal with some special exceptions caused by the server side close
the connection
+ */
+ .put(IOException.class, Arrays.asList(new String[] {"Connection
reset by peer"}))
+ .put(VertxException.class, Arrays.asList(new String[] {"Connection
was closed"}))
+ .put(NoRouteToHostException.class, Arrays.asList(new String[]{"Host
is unreachable"}))
+ .build();
+
@Override
public boolean isSupport(String key, String value) {
return ACCEPT_KEYS.contains(key) && ACCEPT_VALUES.contains(value);
@@ -53,19 +67,6 @@ public RetryHandler createRetryHandler(String retryName,
String microservice) {
return new DefaultLoadBalancerRetryHandler(
Configuration.INSTANCE.getRetryOnSame(microservice),
Configuration.INSTANCE.getRetryOnNext(microservice), true) {
- private List<Class<? extends Throwable>> retriable = Lists
- .newArrayList(ConnectException.class, SocketTimeoutException.class);
-
- Map<Class<? extends Throwable>, List<String>> strictRetriable =
- ImmutableMap.<Class<? extends Throwable>, List<String>>builder()
- .put(ConnectException.class, Lists.newArrayList())
- .put(SocketTimeoutException.class, Lists.newArrayList())
- /*
- * deal with some special exceptions caused by the server side
close the connection
- */
- .put(IOException.class, Lists.newArrayList(new String[]
{"Connection reset by peer"}))
- .put(VertxException.class, Lists.newArrayList(new String[]
{"Connection was closed"}))
- .build();
@Override
public boolean isRetriableException(Throwable e, boolean sameServer) {
@@ -80,11 +81,6 @@ public boolean isRetriableException(Throwable e, boolean
sameServer) {
return retriable;
}
- @Override
- protected List<Class<? extends Throwable>> getRetriableExceptions() {
- return this.retriable;
- }
-
public boolean isPresentAsCause(Throwable throwableToSearchIn) {
int infiniteLoopPreventionCounter = 10;
while (throwableToSearchIn != null && infiniteLoopPreventionCounter >
0) {
diff --git
a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestDefaultRetryhandler.java
b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestDefaultRetryhandler.java
index 8535a5aef..99faf1e6a 100644
---
a/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestDefaultRetryhandler.java
+++
b/handlers/handler-loadbalance/src/test/java/org/apache/servicecomb/loadbalance/TestDefaultRetryhandler.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.net.ConnectException;
+import java.net.NoRouteToHostException;
import java.net.SocketTimeoutException;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
@@ -86,6 +87,19 @@ public void testRetryVertxException() {
Assert.assertFalse(retriable);
}
+ @Test
+ public void testRetryNoRouteToHostException() {
+ Exception target = new NoRouteToHostException("Host is unreachable");
+ Exception root = new Exception(target);
+ boolean retriable = retryHandler.isRetriableException(root, false);
+ Assert.assertTrue(retriable);
+
+ target = new NoRouteToHostException("Cannot assign requested address");
+ root = new Exception(target);
+ retriable = retryHandler.isRetriableException(root, false);
+ Assert.assertFalse(retriable);
+ }
+
@Test
public void testRetryInvocation503() {
Exception root = new InvocationException(503, "Service Unavailable",
"Error");
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> add NoRouteToHostException in retry's exception
> -----------------------------------------------
>
> Key: SCB-1012
> URL: https://issues.apache.org/jira/browse/SCB-1012
> Project: Apache ServiceComb
> Issue Type: Bug
> Components: Java-Chassis
> Affects Versions: java-chassis-1.0.0
> Reporter: WeiChao
> Assignee: WeiChao
> Priority: Major
> Fix For: java-chassis-1.1.0
>
>
> When using container deployment, the NoRouteToHostException("Host is
> unreachable") is thrown when the container hangs and cannot be accessed. The
> retry mechanism does not take effect.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)