Fix connection pool reuse: HTTP/1.1 is persistent by default (RFC 7230)#46
Open
owner888 wants to merge 1 commit into
Open
Fix connection pool reuse: HTTP/1.1 is persistent by default (RFC 7230)#46owner888 wants to merge 1 commit into
owner888 wants to merge 1 commit into
Conversation
…equire explicit keep-alive header
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.
What
Fix connection pool reuse: treat HTTP/1.1 connections as persistent by default (RFC 7230 §6.3), instead of requiring both request and response to carry an explicit
Connection: keep-aliveheader.Why
recycleConnectionFromRequest()currently closes the connection unless both sides literally sentConnection: keep-alive:Real-world HTTP/1.1 servers (nginx, Google frontends, most CDNs) omit the
Connectionheader because persistence is the protocol default. As a result the pool closes every connection after each response and never actually reuses any — every request pays a fresh TCP + TLS handshake.Per RFC 7230 §6.3, an HTTP/1.1 connection persists unless either side explicitly signals
close.Benchmark
Streaming requests against
generativelanguage.googleapis.com(20 samples each, time-to-first-byte):~130ms saved per request once the pool warms up.
Notes
process()already handles it via the existinggetStatus()→reconnect()path, so pooling a to-be-closed connection is safe.