【问题标题】:Invasive AsyncRequestTimeoutException with Spring Boot 2Spring Boot 2 的侵入性 AsyncRequestTimeoutException
【发布时间】:2018-08-26 18:51:14
【问题描述】:

有人能解释一下这个异常的原因以及如何有效地解决它吗?我不想实施here 提供的解决方案,因为它可能会产生一些副作用。当控制器的处理程序返回 SseEmitter 时会发生此异常。

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

以上代码原因:

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

谢谢

【问题讨论】:

  • 这是可能与stackoverflow.com/questions/39856198/…重复的问题
  • @hieund 不重复,因为第一篇文章是关于 Spring Boot Admin
  • @akuma8 你找到解决办法了吗?
  • @Ozilophile 不幸的是,没有!我决定忽略它并禁用它的日志记录。如果您找到解决方案,请告诉我。
  • 我也发现了这种异常。除此之外,我注意到HttpMediaTypeNotAcceptableException 也被抛出,就在SseEmitter 超时之后。

标签: spring-mvc spring-boot server-sent-events


【解决方案1】:

Tomcat 中的默认超时为 30 秒,但您可以使用 public SseEmitter(Long timeout) 构造函数为此方法指定其值。超时值以毫秒为单位。

【讨论】:

  • 这个答案应该有什么帮助?
  • new SseEmitter(0) 禁用超时,或者您可以传递一些足够大的值,例如 1 小时。
【解决方案2】:

如果你在 SseEmitter 上调用“完成”,你可以阻止 org.springframework.web.context.request.async.AsyncRequestTimeoutException

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

【讨论】:

    猜你喜欢
    • 2019-10-25
    • 2017-02-12
    • 2019-07-12
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    相关资源
    最近更新 更多