feat: configurable, reused DB connection pool - #425
Closed
jabbrwcky wants to merge 0 commit into
Closed
Conversation
jabbrwcky
force-pushed
the
feat/configurable-connection-pool
branch
3 times, most recently
from
July 23, 2026 12:55
b546801 to
b072699
Compare
jabbrwcky
force-pushed
the
feat/configurable-connection-pool
branch
from
August 18, 2026 12:05
b072699 to
fe39828
Compare
Contributor
Author
|
Superseded by #434 (same branch got wiped by a bad rebase, GitHub wouldn't let this PR reopen after recovery). |
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.
Description of your changes
Every DB client previously opened a new
*sql.DBviasql.Openon every query and closed it immediately, so the provider held an effectively unbounded number of short-lived connections against each server.This PR introduces a process-wide, DSN-keyed connection-pool cache (
pkg/clients/pool): managed resources targeting the same server (driver + DSN) now share a single bounded*sql.DB. Pools applyMaxOpenConns/MaxIdleConns/ConnMaxLifetime/ConnMaxIdleTimeand are evicted after going idle, so a credential rotation (new DSN) does not leak pools.The pool is tunable per
ProviderConfig/ClusterProviderConfigvia a new optionalconnectionPoolblock, for all three databases (MySQL, PostgreSQL, MSSQL), cluster- and namespaced-scoped. Omitted fields use defaults:maxOpenConnections=10,maxIdleConnections=5,maxConnLifetime=1h,maxConnIdleTime=10m.Notable design points for reviewers:
xsql.DBinterface intentionally gains noClose(): the cache owns pool lifecycle, so the per-controllerDisconnectmethods stay no-ops.(driver, DSN); the config that first creates a pool for a DSN wins (in practice a DSN maps to one ProviderConfig).connectionPool, so existing ProviderConfigs keep working unchanged.See
docs/connection-pool.mdfor details.Fixes #195
I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
makeandmake reviewablepass (generate is a no-op diff, lint and fullgo test ./...are green).🤖 Generated with Claude Code