Repository navigation
Compare the HTTP connection store limit against stored connections, not the group total - #119078
Conversation
…ot the group total `isStoreLimitReached` compared `store_limit` against `total_connections_in_group`, which counts the connections in use as well as the stored ones. Once the concurrency of a group exceeded the limit, `atConnectionDestroy` reset every connection after use and the pool cached nothing at all: each request to object storage opened and closed its own TCP connection, and the churn exhausted the ephemeral port range of the host with sockets in `CLOSE-WAIT`. Lowering the setting made it strictly worse. The `ConnectionGroup` now counts the stored connections separately. A slot is reserved under the group mutex before a connection is stored, so endpoint pools of the same group cannot overshoot the limit together, and it is released when a stored connection is reused, expires, or is dropped with its pool. The `*ConnectionsStored` current metrics are maintained through the same counter. The descriptions of the `*_connections_store_limit` settings now say what the limit bounds. Closes: #119072 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Workflow [PR], commit [29fb966] Summary: ✅
AI ReviewSummaryThis PR fixes the HTTP connection pool so Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 29fb966.
Changed lines: Changed C/C++ lines covered: 81/84 (96.43%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 28 s compile time in total, 9 of them have a recent master baseline. |
|
It's like a miracle! |
Closes: #119072
disk_connections_store_limit(and thestorage_*/http_*counterparts) was compared against the total number of connections in the group, active plus stored, rather than against the number of connections actually stored. As soon as the concurrency of a group exceeded the limit, the pool stopped caching entirely: every HTTP request to object storage opened a new TCP connection and closed it after use, and on a busy writer the churn exhausted the ephemeral port range of the host with tens of thousands of sockets inCLOSE-WAIT. The failure surfaced asCannot assign requested addressfrom Poco rather than as a ClickHouse limit. Lowering the setting, the intuitive reaction to "too many connections", made it strictly worse.The connection group now keeps a separate count of stored connections, and the store limit is checked against that count. The slot is reserved atomically before the connection is stored, so endpoint pools of the same group cannot overshoot the limit together; it is released when a stored connection is reused, expires, or is dropped with its pool. The
*ConnectionsStoredcurrent metrics are maintained through the same counter. The setting descriptions now say what the limit bounds.The unit test holds five connections with a store limit of two and checks that releasing two of them while three are still in use stores both, that the store then stays full, and that reusing a stored connection frees its slot.
Not changed here, from the other two suggestions in the issue: the default
*_connections_hard_limitstays at 200000, because the ephemeral port range is consumed per destination address and a group that talks to many endpoints can legitimately hold more connections than one address allows. Stale connections that are not at the top of the expiry heap are still reaped only when they reach it, at the next borrow or sweep.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix the HTTP connection pool comparing
disk_connections_store_limit,storage_connections_store_limit, andhttp_connections_store_limitagainst the total number of connections in the group instead of the number of stored connections. A server whose concurrency exceeded the limit cached no connections at all, opened a new TCP connection for every request to object storage, and could exhaust the ephemeral port range of the host. The limit now bounds only the idle connections kept for reuse.Workflow [PR]
Sync PR [sync-upstream/pr/119078]
Version info
26.9.1.1172(included in26.9and later)