Skip to content

fix: add DB connection pooling and reduce MySQL pool defaults#57

Merged
jgowdy merged 2 commits intomainfrom
fix/db-connection-pooling
Mar 14, 2026
Merged

fix: add DB connection pooling and reduce MySQL pool defaults#57
jgowdy merged 2 commits intomainfrom
fix/db-connection-pooling

Conversation

@jgowdy-godaddy
Copy link
Collaborator

Summary

  • MySQL: Reduce default pool from min=10/max=100 to min=0/max=10, matching Go database/sql behavior of not pre-creating connections. Existing user-provided pool_min/pool_max URL params are respected. Configurable via ASHERAH_POOL_SIZE env var.
  • PostgreSQL: Add connection pooling where previously every query opened a new TCP+TLS connection. Pool tracks max_open=10 and max_idle=2 (matching Go's database/sql MaxIdleConns default). Connections returned to pool on scope exit via Drop, with stale connection detection via is_closed(). Returns error if pool exhausted.

Fixes "1040: Too many connections" errors seen in Test with Aurora MySQL when multiple services/processes share the same database.

Test plan

  • All 571 cargo test -p asherah --features mysql,postgres tests pass
  • cargo clippy clean with -D warnings
  • Pre-commit hooks (fmt, clippy, test) pass
  • Verify against Aurora MySQL test environment — connection count should stay bounded
  • Verify Postgres metastore reuses connections under load instead of creating new ones per query

MySQL: reduce default pool from min=10/max=100 to min=0/max=10,
matching Go database/sql behavior of not pre-creating connections.
Respects user-provided pool_min/pool_max URL params and ASHERAH_POOL_SIZE
env var.

PostgreSQL: add connection pooling where previously every query opened a
new TCP+TLS connection. Pool tracks max_open=10 and max_idle=2 (matching
Go database/sql MaxIdleConns default). Connections returned to pool on
scope exit via Drop, with stale connection detection via is_closed().
With min=0 pool connections, Pool::new() no longer pre-creates connections,
so connect() succeeds even with a bad URL. The error now surfaces on first
use, matching the Postgres test pattern.
@jgowdy jgowdy merged commit e13081d into main Mar 14, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants