2

Could someone explain me the reason of this exception and how to efficiently solve it? I don't want to implement the solution provided here since it could have some side effects. This exception occurs when a controller's handler returns a SseEmitter.

@GetMapping("/sse")
SseEmitter registerClient(){
  SseEmitter emitter = new SseEmitter()
  return emitter;
}

The code above causes:

org.springframework.web.context.request.async.AsyncRequestTimeoutException: null
    at org.springframework.web.context.request.async.TimeoutDeferredResultProcessingInterceptor.handleTimeout(TimeoutDeferredResultProcessingInterceptor.java:42)
    at org.springframework.web.context.request.async.DeferredResultInterceptorChain.triggerAfterTimeout(DeferredResultInterceptorChain.java:79)
    at org.springframework.web.context.request.async.WebAsyncManager.lambda$startDeferredResultProcessing$5(WebAsyncManager.java:426)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at org.springframework.web.context.request.async.StandardServletAsyncWebRequest.onTimeout(StandardServletAsyncWebRequest.java:151)
    at org.apache.catalina.core.AsyncListenerWrapper.fireOnTimeout(AsyncListenerWrapper.java:44)
    at org.apache.catalina.core.AsyncContextImpl.timeout(AsyncContextImpl.java:136)
    at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:153)
    at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:236)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)
2018-08-25 | 20:49:00.116 | http-nio-8080-exec-3 |  WARN | o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver | Resolved exception caused by Handler execution: org.springframework.web.context.request.async.AsyncRequestTimeoutException

Thanks

akuma8
  • 4,160
  • 5
  • 46
  • 82
  • It is posibility dubplicated question with https://stackoverflow.com/questions/39856198/recurring-asyncrequesttimeoutexception-in-spring-boot-admin-log – hieund Oct 03 '18 at 10:24
  • @hieund not duplicate as the first post is about Spring Boot Admin – akuma8 Oct 03 '18 at 10:40
  • @akuma8 have you found a solution to this? – unlimitednzt Oct 18 '18 at 13:33
  • @Ozilophile Unfortunatly no! I decided to ignore it and disable its logging. If you find a solution please let me know. – akuma8 Oct 18 '18 at 14:02
  • I've also found such kind of exception. Besides this, i've noticed that a ```HttpMediaTypeNotAcceptableException``` is also thrown, just after the ```SseEmitter``` timeout. – user8510613 Jun 08 '20 at 08:05

2 Answers2

2

If you invoke "complete" on the SseEmitter you can prevent the org.springframework.web.context.request.async.AsyncRequestTimeoutException

SseEmitter sseEmitter = new SseEmitter(1L);
sseEmitter.onTimeout(sseEmitter::complete); // prevent AsyncRequestTimeoutException on timeout
Akim
  • 21
  • 3
1

The default timeout in Tomcat is 30 seconds, but you specify its value for this method using the public SseEmitter(Long timeout) constructor. The timeout value is in milliseconds.

Alex Panchenko
  • 452
  • 2
  • 6