Spray.can.server.request-超时属性没有效果

Spray.can.server.request-timeout property has no effect

在我的 src/main/resources/application.conf 我包括:

spray.can.server {
  request-timeout = 1s
}

为了对此进行测试,在为我的请求提供服务的 Future 中,我放置了一个 Thread.sleep(10000).

当我发出请求时,服务器等待 10 秒并响应,但没有向客户端发送超时提示。

我没有覆盖超时处理程序。

为什么我的客户(chrome 和 curl)没有收到超时?

我认为request-timeout是针对http客户端的,如果在该值之前没有返回响应,客户端会从spray中获得超时,见spary doc

  # If a request hasn't been responded to after the time period set here
  # a `spray.http.Timedout` message will be sent to the timeout handler.
  # Set to `infinite` to completely disable request timeouts.

例如,在我的网络浏览器中,我可以收到以下消息:

Ooops! The server was not able to produce a timely response to your request.
Please try again in a short while!

如果超时时间足够长,浏览器会一直等待直到返回响应

配置看起来正确,因此喷射请求超时应该有效。它不起作用的常见原因之一是您的配置 application.conf 未被应用程序使用。

配置被忽略的原因可能是它位于错误的位置,未包含在您的类路径中,或者未包含在您打包的 JAR 中。

要排除故障,请先检查默认的喷射超时是否有效。通过 default 是 20 秒。让您的代码休眠 30 秒,看看是否触发了超时。

通过 printing it 检查最终配置值中的内容。在您的会议中设置:

akka {
  # Log the complete configuration at INFO level when the actor system is started.
  # This is useful when you are uncertain of what configuration is used.
  log-config-on-start = on
}

最后,请记住其他超时,例如 timeout-timeout = 2 s