Bugfix HTTP/2 keep_alive_max_requests dropping the requests in flight - #377
Open
harryherbig wants to merge 1 commit into
Open
harryherbig wants to merge 1 commit into
harryherbig wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On HTTP/2, reaching
keep_alive_max_requestscalledclose_connection()right away, on the request that exceeded the limit. h2 moves to the CLOSED state on GOAWAY, where it refuses to send HEADERS or DATA, so every stream still in flight on that connection lost its response (stream_sendswallows theProtocolError). The GOAWAY'slast_stream_idcovers those streams, so the client cannot safely retry them either.With a multiplexing client that keeps one long-lived connection (grpc, Envoy, browsers) this fails the 1001st request plus everything in flight next to it, every 1000 requests. Measured with a grpcio client sending 3000 unary calls at concurrency 50 over one connection:
keep_alive_max_requestsThe fix mirrors the shutdown path that already exists in
H2Protocol: when the limit is reached, announceSETTINGS_MAX_CONCURRENT_STREAMS = 0, keep serving the streams already in flight (including ones the client sent before it saw the setting), and send the GOAWAY once the connection is idle. The connection is then closed by the server, as the HTTP/1.1 path does afterconnection: close, instead of lingering until the keep-alive timeout. This is the HTTP/2 counterpart of #227.test_protocol_keep_alive_max_requestsnow drives three streams into the protocol with a limit of two and asserts the sequence: settings go to zero, nothing is reset or terminated while streams are open, GOAWAY andClosedfollow the lastStreamClosed.No httpx end-to-end test: httpcore ignores a
max_concurrent_streamsof zero (if max_concurrent_streams:in_receive_remote_settings_change) and h2 then raisesLocalProtocolErroron the client side for any further request in the drain window. grpc-core and Envoy handle the setting as intended.