akka http配置中idle-timeout和request timeout之间有什么区别?

时间:2017-06-22 07:06:57

标签: scala akka-http connection-timeout

我去了文档,发现了这些    #空闲连接自动关闭的时间。     #设置为infinite以完全禁用空闲连接超时。     idle-timeout = 10 s

# Defines the default time period within which the application has to
# produce an HttpResponse for any given HttpRequest it received.
# The timeout begins to run when the *end* of the request has been
# received, so even potentially long uploads can have a short timeout.
# Set to `infinite` to completely disable request timeout checking.
#
# If this setting is not `infinite` the HTTP server layer attaches a
# `Timeout-Access` header to the request, which enables programmatic
# customization of the timeout period and timeout response for each
# request individually.
request-timeout = 20 s

我的情况是我的服务器处理响应的时间超过10秒,但在发送HTTPResponse之前,客户端和服务器之间的TCP连接由于空闲超时而超时。

虽然此时连接处于空闲状态,但请求仍在处理中。

我认为这是响应超时的责任?

这个上下文中的任何人都可以解释一下idle-timeout和response-timeout之间的区别吗?

2 个答案:

答案 0 :(得分:2)

文档有点混乱,我已经基于此进行了实验:

空闲超时:这是连接可以空闲的最长时间。它的行为与“请求超时”相同。示例:

空闲超时= 1秒

应用程序已向第3方API发送了一个请求,并建立了连接,但第3方未回复。然后您将收到一个Timeout异常。

“ akka.stream.scaladsl.TcpIdleTimeoutException”

连接超时:500毫秒。表示必须建立Http连接的最长时间(500毫秒)。

答案 1 :(得分:0)

来自documentationmore details here

  # The idle timeout for an open connection after which it will be closed
  # Set to null or "infinite" to disable the timeout, but notice that this
  # is not encouraged since timeout are important mechanisms to protect your
  # servers from malicious attacks or programming mistakes.
  idleTimeout = 75 seconds

如果您将空闲超时设置为低于请求超时,那么它优先。您的空闲超时设置应该长于请求超时,因此对于每个请求,请求超时决定何时关闭连接。