Repository navigation
perf: ⚡ Pool idle upstream connections per host - #1571
Conversation
Signed-off-by: Evaline Ju <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Set and verify per-host limits core/listener/forwardproxy/server.go, core/tlsbridge/upstream.go, core/listener/forwardproxy/maxidle_test.go, core/tlsbridge/upstream_test.go |
Both transports set MaxIdleConnsPerHost to 100. Tests verify the configured limit for each transport. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- Source audit for
http.Transportliterals (1554): This change updates two transport literals but does not add the proposed source audit.
Suggested reviewers: huang195
Merge Risk: 
Minimal · up to 1527d
-
The change raises the per-host idle connection limits; no merge-blocking risk is established.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Out of Scope Changes check
-
Explanation
The changed production code implements issue
#1546in the two named transports. The added tests verify the new transport configuration. No unrelated production behavior or unrelated files are identified.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 4 files.
-
Full details: Linked Issues check
-
Explanation
Issue
#1546requiresMaxIdleConnsPerHost: 100for both upstream transports and an automated concurrency check that demonstrates approximately one connection per worker. The PR adds the field incore/listener/forwardproxy/server.goandcore/tlsbridge/upstream.go. The new tests only inspect the configured field. They do not verify connection reuse under repeated concurrent requests.Resolution
Add a deterministic automated test for the issue's repeated-concurrency acceptance criterion. The test must exercise the upstream client against an HTTP/1.1 origin, count accepted connections, and assert that the count is approximately the worker count. Keep the direct transport-field checks if useful.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
huang195
left a comment
There was a problem hiding this comment.
Sets MaxIdleConnsPerHost: 100 on both upstream transports so connection count follows caller count rather than request count on h1-only upstreams. Direct field assertions in the tests are the right call here — a behavioral test would need real dial latency to force overlap. One nit inline; otherwise clean.
| // Sane Go defaults for everything except DialContext, which we | ||
| // customize when mTLS is on. | ||
| MaxIdleConns: 100, | ||
| MaxIdleConns: 100, |
There was a problem hiding this comment.
nit: With MaxIdleConnsPerHost: 100 but the global MaxIdleConns still at 100, a single busy host can hold the entire idle pool — fine while LiteLLM dominates, but if you ever want headroom for LiteLLM + Keycloak concurrently, the global cap is the one to raise.
Brings in the commits that landed while this branch was in review — #1561 (reload in-flight pipelines), #1562 (forgeable headers), #1563 (token cache scope key), #1564 (tlsbridge bind redaction), #1571 (max-idle) and the rest — and resolves the one real conflict they create here. ONE CONFLICT, in forwardproxy.serveOutbound, and both sides were needed: - main (#1561) introduced `pinned := s.OutboundPipeline.ForPctx(pctx)` so every capability probe for the rest of the handler answers for the pipeline the request actually ran on rather than whatever a mid-request reload left in the Holder, and switched ownEncoding's two probes onto it. - this branch had added stripForUpstream's third parameter, keepUpgrade, so a forwarded WebSocket keeps its normalized Connection/Upgrade pair. Main's version dropped the third argument because it did not have one; taking either side alone would have lost the other. Resolved as main's pinned probes calling stripForUpstream(r, ownEncoding, forwardUpgrade). Checked rather than assumed, since the last merge of this shape hid a semantic conflict behind a green build: every stripForUpstream call site passes three arguments (serveOutbound's, and resendIfAsked's keepUpgrade=false), and the WebSocket relay makes no capability probe of its own, so there is nothing in it that #1561's pinning should have moved — the one later probe in the function, WritesResponseBody, is already on `pinned`. #1562 touches extproc and auth, not the forward proxy's hop-by-hop handling, so it does not meet this feature. Everything else auto-merged, including all three of this branch's doc edits (framework-architecture.md's two upgrade conditions, CLAUDE.md's and session-api.md's 101-row semantics), each verified present afterwards. core go test 73 ok (core/plugins and core/plugins/opa fail to build for lack of a cgo toolchain here, as on unmodified main); the 17 upgrade tests and both usage tests pass; reloader and the whole listener tree clean; forwardproxy clean under -race -count=2; cmd/cortex ok; gofmt, go vet and go mod tidy -diff clean on both touched modules. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Mariusz Sabath <[email protected]>
Summary
The forward proxy and TLS bridge set
MaxIdleConns: 100but notMaxIdleConnsPerHost, so Go's default of 2 applied and more than two concurrent callers to one upstream opened a fresh TCP+TLS per request. Set the field to 100 on both transports.Tests assert the field directly: a behavioral test needs real dial latency to force overlap, which localhost httptest on a fast machine doesn't provide.
Assisted-By: Claude (Anthropic AI) [email protected]
Related issue(s)
Fixes #1546
Summary by CodeRabbit