fix: reserve ephemeral-port headroom for the auto max-connections default#407
fix: reserve ephemeral-port headroom for the auto max-connections default#407nvzhihanj wants to merge 1 commit into
Conversation
…ault max_connections=-1 resolved to the entire ephemeral-port range (system_maximum_ports x distinct_endpoints). Establishing connections in a burst (e.g. max_throughput at start-up) then tries to bind every ephemeral port at once; with recently-closed ports held in TIME_WAIT, the tail of bind() calls intermittently fails with EADDRNOTAVAIL. Resolve the auto limit to a fraction of the budget (AUTO_MAX_CONNECTIONS_BUDGET_FRACTION = 0.5) so the zero-config default reserves headroom; an explicit max_connections may still use the full budget. Remove the now-dead get_ephemeral_port_limit / get_used_port_count. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
There was a problem hiding this comment.
Code Review
This pull request updates the automatic connection limit calculation to only claim a fraction (50%) of the ephemeral-port budget, leaving headroom for the OS to prevent connection establishment failures. Additionally, unused port-counting utility functions have been removed, and the unit tests have been updated and expanded to verify the new behavior. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Problem
client.max_connectionsdefaults to-1, which resolves to the entireephemeral-port range (
system_maximum_ports × distinct_endpoints). Whenconnections are established in a burst — e.g.
max_throughputat start-up — thepool tries to bind every ephemeral port at once. The OS holds recently-closed
ports in
TIME_WAIT, so the tail ofbind()calls intermittently fails withEADDRNOTAVAIL("Cannot assign requested address"). The run recovers, but onlyafter a burst of dropped/retried connections; it's worst when the client shares a
host with other socket activity.
A connection pool should never try to claim 100% of the ephemeral range — that
leaves nothing for
TIME_WAITrecycling, the OS, or other processes on the box.Fix
Resolve the auto (
-1) limit to a fraction of the budget instead of the wholerange, so the zero-config default reserves headroom:
AUTO_MAX_CONNECTIONS_BUDGET_FRACTION = 0.5— auto claims half the per-endpointbudget. That is still a large pool (thousands of connections per endpoint) and
continues to scale with the number of distinct endpoints.
max_connectionsis unchanged and may still use the fullbudget (the over-budget guard is unchanged).
Also removes the now-dead
get_ephemeral_port_limit()/get_used_port_count()helpers — the static reserve replaces them without reading the racy,
process-global live socket count.
Why this default
The client should work well without the user having to reason about ephemeral
ports or hand-tune
max_connections. A static reserve keeps that property: thedefault is safe on a busy/co-located host, while workloads that genuinely need
more concurrency add endpoints (the budget scales per distinct destination) or
set an explicit value. Empirically, claiming the full range reliably produced
EADDRNOTAVAILunder a burstymax_throughputstart-up, whereas reservingheadroom eliminated it with no change to server-side batch or throughput.
Tests
Updated
TestEndpointBudgetScalingfor the reserved-headroom default and added acase asserting the auto limit leaves headroom while an explicit value may use the
full budget.
🤖 Generated with Claude Code