响应流有时会导致“按对等方重置连接”错误

问题描述 投票:1回答:1

在我们的应用程序中,我们有流式JSON文档的路由。这是一个例子:

/** GET api/1/tenant/(tenantId)/ads/ */
def getAllAdsByOwner(advertiserId: AdvertiserId): Route =
  get {
    httpRequiredSession { username =>
      getAllTenantAds(username, advertiserId) { (adSource: Source[AdView, Any]) =>
        complete(adSource)
      }
    }
  }

大部分时间它按预期工作,但有时,特别是当有许多同时请求时,服务器在标头发送后立即开始重置连接。我测试了一个脚本,该脚本在循环中使用curl请求此路由,并在请求失败时中止。在停止前它运行了大约2分钟。请求失败时跟踪如下:

<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 54 bytes (0x36)
0000: Access-Control-Allow-Origin: https://<...>
<= Recv header, 135 bytes (0x87)
0000: Access-Control-Expose-Headers: Content-Type, Authorization, Refr
0040: esh-Token, Set-Authorization, Set-Refresh-Token, asset-content-l
0080: ength
<= Recv header, 40 bytes (0x28)
0000: Access-Control-Allow-Credentials: true
<= Recv header, 24 bytes (0x18)
0000: Content-Encoding: gzip
<= Recv header, 23 bytes (0x17)
0000: X-Frame-Options: DENY
<= Recv header, 33 bytes (0x21)
0000: X-Content-Type-Options: nosniff
<= Recv header, 26 bytes (0x1a)
0000: Content-Security-Policy: .
<= Recv header, 20 bytes (0x14)
0000: default-src 'self';.
<= Recv header, 63 bytes (0x3f)
0000: style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;.
<= Recv header, 59 bytes (0x3b)
0000: font-src 'self' 'unsafe-inline' https://fonts.gstatic.com;.
<= Recv header, 99 bytes (0x63)
0000: script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.google
0040: apis.com https://maps.gstatic.com;.
<= Recv header, 69 bytes (0x45)
0000: img-src 'self' data: https://*.googleapis.com https://*.gstatic.
0040: com;.
<= Recv header, 8 bytes (0x8)
0000:
<= Recv header, 26 bytes (0x1a)
0000: Server: akka-http/10.1.3
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 27 Jun 2018 15:20:24 GMT
<= Recv header, 28 bytes (0x1c)
0000: Transfer-Encoding: chunked
<= Recv header, 32 bytes (0x20)
0000: Content-Type: application/json
<= Recv header, 2 bytes (0x2)
0000:
== Info: Recv failure: Connection reset by peer
== Info: stopped the pause stream!
== Info: Closing connection 0
curl: (56) Recv failure: Connection reset by peer

Wireshark检查了同样的请求:

screen shot

阅读日志并未提供有关问题可能来源的任何暗示。响应记录为成功:

[27-06-2018 19:44:52.837][INFO] access: 'GET /api/1/tenant/ca764a91-8616-409c-8f08-c64a40d3fc07/ads' 200 596ms

二手软件的版本:

  • 比例:2.11.11
  • 啊:2.5.13
  • akka-http:10.1.3

组态:

我尝试将akka.http.host-connection-pool.max-connections增加到128但它没有帮助。也许有人知道这是否是akka-http或配置问题中的错误?

scala http stream akka akka-http
1个回答
1
投票

如果您的打开连接上没有用于空闲超时的I / O,则Akka将关闭通常显示为“通过对等方重置连接”错误的连接。尝试增加akka.http.server.idle-timeout值。

因为您的akka​​.http.server.request-timeout值与akka.http.server.idle-timeout相同,所以它是一种竞争条件,在没有I / O的情况下,首先会发生超时。有时,你会看到503;其他时候,您将遇到连接重置错误。

© www.soinside.com 2019 - 2024. All rights reserved.