swift-server / async-http-client

HTTP client library built on SwiftNIO
https://swiftpackageindex.com/swift-server/async-http-client/main/documentation/asynchttpclient
Apache License 2.0
916 stars 118 forks source link

[HTTP2] Count down available streams in HTTP2Connections #506

Open fabianfett opened 2 years ago

fabianfett commented 2 years ago

Currently we don't make sure that we schedule a maximum of Int32.max/2 (= 1073741823) on a single HTTP2Connection. We should do so in the connection and regular communicate the remaining streams back to the HTTPConnectionPool.

To allow use cases like querying services behind AWS ALB we should also make the starting max number configurable for users. If a user knows they will use AWS ALB, they should be able to configure 10k max streams on the client.

fabianfett commented 2 years ago

AWS Application Load Balancer seems to send a GOAWAY after 10k streams:

▿ FramePayload
  ▿ goAway : 3 elements
    ▿ lastStreamID : HTTP2StreamID(19999)
      - networkStreamID : 19999
    ▿ errorCode : HTTP2ErrorCode<0x0 No Error>
      - _networkCode : 0
    - opaqueData : nil

The load balancer sends a response code of 000

With HTTP/2 connections, if the compressed length of any of the headers exceeds 8K bytes or if the number of requests served through one connection exceeds 10,000, the load balancer sends a GOAWAY frame and closes the connection with a TCP FIN.

https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-troubleshooting.html