I am writing configuration for spring-boot application. I am using WebMvcConfigurer
interface. I have set default timeout as 30 seconds as I have used SseEmitter()
for event handling (as SseEmitter
has by default timeout of 30 seconds). However, after 30 seconds, it gives warning Async request timed out
. Is there a way to set timeout again or to handle this error? Please help me how to resolve this issue.
Thanks in advance :)
This is what I have written.
@Configuration
public class EventConfiguration implements WebMvcConfigurer {
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
configurer.setDefaultTimeout(30000);
}
}
I am getting following errors:
2019-10-30 11:35:02.711 WARN 10728 --- [nio-8090-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Async request timed out
2019-10-30 11:35:02.712 WARN 10728 --- [nio-8090-exec-3] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.context.request.async.AsyncRequestTimeoutException]
2019-10-30 11:35:03.699 WARN 10728 --- [nio-8090-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Async request timed out
2019-10-30 11:35:03.701 WARN 10728 --- [nio-8090-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.context.request.async.AsyncRequestTimeoutException]
If you want to simply handle the exception then you can write an exception handler for the same, something like below
@ExceptionHandler(AsyncRequestTimeoutException.class)
public final ResponseEntity<Object> handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, WebRequest request) {
....
....
}
If you want to do more, you can write your own TimeoutCallableProcessingInterceptor
@Bean
public CallableProcessingInterceptor callableProcessingInterceptor() {
return new TimeoutCallableProcessingInterceptor() {
@Override
public <T> Object handleTimeout(NativeWebRequest request, Callable<T> task) throws Exception {
log.error("timeout!");
return super.handleTimeout(request, task);
}
};
}
Note I have not tried this, let us know if it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With