Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +46,18 @@ public class DefaultRetryExtensionsFactory implements ExtensionsFactory {
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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down