Skip to content

feat(quaint): expose pool health check options as connection string parameters - #5846

Open
YuzuruS wants to merge 1 commit into
prisma:mainfrom
YuzuruS:feat/pool-health-check-params
Open

feat(quaint): expose pool health check options as connection string parameters#5846
YuzuruS wants to merge 1 commit into
prisma:mainfrom
YuzuruS:feat/pool-health-check-params

Conversation

@YuzuruS

@YuzuruS YuzuruS commented Jul 24, 2026

Copy link
Copy Markdown

Overview

The pooled Builder has long supported test_on_check_out and health_check_interval, and QuaintManager::check is already implemented as a SELECT 1 ping — but no connector URL parser exposes either option. Since Prisma builds its pool exclusively from the datasource URL via Quaint::builder_with_tracing, the health-check machinery is effectively dead code for Prisma users.

This PR makes both options parseable from the connection string for PostgreSQL, MySQL and SQL Server, following the exact pattern of the existing max_connection_lifetime / max_idle_connection_lifetime parameters.

New parameters

Parameter Type Default Behavior
test_on_check_out bool false When true, a connection is verified with SELECT 1 before being handed out of the pool. A connection that was silently severed while idle (NAT/LB idle timeout, server-side reset) is discarded and transparently replaced instead of failing the query with a connection error.
health_check_interval seconds none Only meaningful with test_on_check_out=true: rate-limits the check to at most once per interval per connection (mobc marks the connection checked). 0 or omitted = verify every checkout.

SQL Server also accepts testOnCheckOut / healthCheckInterval, consistent with its other JDBC-style parameters (keys are case-normalized by the JDBC parser).

SQLite is intentionally excluded: an embedded file database has no network path that can go stale.

Why

Long-running deployments (ECS/Fargate, EC2, Kubernetes) hold pooled connections long enough for middleboxes or the server to sever them while idle. The next checkout hands out a dead connection and the query fails with an intermittent, hard-to-reproduce P1001/P1017 — the recurring theme behind reports like prisma/prisma#13770. Borrow-time validation is the standard remedy in every mainstream pool (HikariCP connectionTestQuery, pgbouncer server_check_query, tarn/knex afterCreate validation, etc.); quaint already has the mechanism, it just cannot be switched on.

Companion issue with a fully-correlated production trace (app logs + RDS system_health Extended Events): prisma/prisma#29786

Changes

  • quaint/src/connector/postgres/url.rs — parse both params + getters
  • quaint/src/connector/mysql/url.rs — parse both params + getters
  • quaint/src/connector/mssql/url.rs — parse both params (camelCase + snake_case) + getters
  • quaint/src/pooled.rs — wire both params into the Builder in builder_with_tracing for the three connectors; document the parameters in the module docs

No behavior change for existing connection strings (both options default to off; Builder defaults are untouched).

Testing

  • 10 new unit tests covering: parse with values, defaults (disabled), 0 interval normalization, and mssql camelCase/snake_case spellings
    • cargo test -p quaint --features "pooled,all-native" --lib health_check → 10 passed
  • cargo clippy -p quaint --features "pooled,all-native" → no warnings
  • cargo fmt clean

…arams

The pooled Quaint builder has long supported test_on_check_out and
health_check_interval (wired through mobc, with QuaintManager::check
already implemented as a SELECT 1 ping), but neither option was
parseable from a connection string. Since Prisma constructs the pool
exclusively via Quaint::builder_with_tracing from the datasource URL,
the health check machinery was effectively unreachable for Prisma
users.

This exposes both options as connection string parameters for the
PostgreSQL, MySQL and SQL Server connectors, following the exact
pattern of the existing max_connection_lifetime and
max_idle_connection_lifetime parameters:

- test_on_check_out (true/false, default false): verify a connection
  with a lightweight SELECT 1 before handing it out of the pool, so
  connections that were silently severed while idle (NAT/LB idle
  timeouts, server-side resets) are discarded and replaced instead of
  failing the query with a connection error.
- health_check_interval (seconds): rate-limits the check to at most
  once per interval per connection; 0 or omitted checks every
  checkout.

SQL Server accepts both camelCase (testOnCheckOut,
healthCheckInterval) and snake_case spellings, consistent with its
other JDBC-style parameters.

Long-running deployments (ECS/Fargate, EC2, Kubernetes) are the main
beneficiaries: unlike short-lived serverless invocations, their pools
hold connections long enough to hit idle disconnects, which currently
surface as intermittent P1001/P1017 errors.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SaXrs7mjAi4BdWYXQC5HZ4
@CLAassistant

CLAassistant commented Jul 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3ed1dc2b-05e7-4c31-ba06-95bb9f9fc4c1

📥 Commits

Reviewing files that changed from the base of the PR and between 059a7b2 and d0b751a.

📒 Files selected for processing (4)
  • quaint/src/connector/mssql/url.rs
  • quaint/src/connector/mysql/url.rs
  • quaint/src/connector/postgres/url.rs
  • quaint/src/pooled.rs

Summary by CodeRabbit

  • New Features

    • Added connection-pool health-check configuration for MySQL, PostgreSQL, and Microsoft SQL Server.
    • Connection strings can now enable health checks when connections are checked out and set a health-check interval.
    • A zero or omitted interval disables periodic health checks, preserving existing defaults.
  • Documentation

    • Documented the new connection parameters and their behavior.

Walkthrough

MySQL, PostgreSQL, and MSSQL connection URL parsers now support checkout testing and health-check interval parameters. The settings default to disabled, with a zero interval represented as no interval. New accessors expose the parsed values. Pool builder construction reads these settings for the three connectors and applies them, while pooled connection documentation describes the parameters and SQLite limitation. Tests cover provided values, defaults, and zero-interval behavior.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: exposing pool health check options via connection string parameters.
Description check ✅ Passed The description accurately describes the implemented URL parsing, builder wiring, connector coverage, and tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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