Skip to content

Spring Retryable – Async context

Have an issue with @Retryable in the Async context, I have a service call which is returning a SocketTimeOut exception. This I would have expected to retry 3 times, I do have @EnableRetry, however I am seeing something I little strange in the logs, a sleep interruptedException. Here is part of the stack trace.

Caused by: java.lang.InterruptedException: sleep interrupted at org.springframework.retry.interceptor.RetryOperationsInterceptor.invoke( ~[spring-retry-1.2.1.RELEASE.jar!/:na] at someservice.somemethod( ~[classes/:na] 2018-01-18 18:59:39.818 INFO 14 — [lTaskExecutor-1] someExceptionHandler : Thread interrupted while sleeping; nested exception is java.lang.InterruptedException: sleep interrupted at org.springframework.retry.backoff.ThreadWaitSleeper.sleep( ~[spring-retry-1.2.1.RELEASE.jar!/:na] at org.springframework.retry.backoff.StatelessBackOffPolicy.backOff( ~[spring-retry-1.2.1.RELEASE.jar!/:na] at [na:1.8.0_141] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept( ~[spring-aop-4.3.8.RELEASE.jar!/:4.3.8.RELEASE] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint( ~[spring-aop-4.3.8.RELEASE.jar!/:4.3.8.RELEASE]

Not sure if this is a red herring here, but this happens after the read timeout occurs, I would have expected it to retry but rather I am seeing this in the logs. I know Spring retry has a default wait of 1 second, I am wondering if its being interrupted thus having an impact on its ability to retry.



Caused by: java.lang.InterruptedException: sleep interrupted at

Simply means that something else in your app is interrupting the thread while it is waiting in the backOff, thus killing the retry scenario.

This is by design…

if (this.logger.isDebugEnabled()) {
            .debug("Abort retry because interrupted: count="
                    + context.getRetryCount());

…when you interrupt a thread, you are explicitly telling it to stop what it’s doing (if it’s doing something interruptible, such as sleeping).