Prevent infinite loop if retry policy fails
This commit is contained in:
@@ -244,7 +244,11 @@ public class RetryTemplate implements RetryOperations {
|
||||
|
||||
doOnErrorInterceptors(retryCallback, context, e);
|
||||
|
||||
registerThrowable(retryPolicy, state, context, e);
|
||||
try {
|
||||
registerThrowable(retryPolicy, state, context, e);
|
||||
} catch (Exception ex) {
|
||||
throw new TerminatedRetryException("Could not register throwable", ex);
|
||||
}
|
||||
|
||||
if (canRetry(retryPolicy, context) && !context.isExhaustedOnly()) {
|
||||
try {
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.retry.ExhaustedRetryException;
|
||||
import org.springframework.retry.RecoveryCallback;
|
||||
import org.springframework.retry.RetryCallback;
|
||||
import org.springframework.retry.RetryContext;
|
||||
import org.springframework.retry.TerminatedRetryException;
|
||||
import org.springframework.retry.backoff.BackOffContext;
|
||||
import org.springframework.retry.backoff.BackOffInterruptedException;
|
||||
import org.springframework.retry.backoff.BackOffPolicy;
|
||||
@@ -246,6 +247,28 @@ public class RetryTemplateTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailedPolicy() throws Exception {
|
||||
RetryTemplate retryTemplate = new RetryTemplate();
|
||||
retryTemplate.setRetryPolicy(new NeverRetryPolicy() {
|
||||
@Override
|
||||
public void registerThrowable(RetryContext context, Throwable throwable) {
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
});
|
||||
try {
|
||||
retryTemplate.execute(new RetryCallback<Object>() {
|
||||
public Object doWithRetry(RetryContext context) throws Exception {
|
||||
throw new RuntimeException("Realllly bad!");
|
||||
}
|
||||
});
|
||||
fail("Expected Error");
|
||||
}
|
||||
catch (TerminatedRetryException e) {
|
||||
assertEquals("Planned", e.getCause().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackOffInterrupted() throws Exception {
|
||||
RetryTemplate retryTemplate = new RetryTemplate();
|
||||
|
||||
Reference in New Issue
Block a user