← Back to Pull requests

Adds pool_params::idle_timeout, closing idle connections above initial_size #538

Open
unknown opened this pull request with 348 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 03, 2026 01:44 UTC
Author

Closes #499.

What it does

Adds pool_params::idle_timeout, zero by default (disabled). A connection that has been idle for idle_timeout is closed and removed from the pool, as long as the pool has more than initial_size connections in any state; the pool never shrinks below initial_size. This works with pings disabled too. The node sends a clean QUIT through async_close, bounded by the new close_timeout; its task exits, the pool erases it, and connections are created again on demand. Idle connections are handed out most recently returned first, so the pool shrinks to what's being used.

Design choices

  • Floor. initial_size bounds the total number of connections, in any state, as it does for growth (changed in review; the first version only counted idle ones). Connections already closing are discounted, so concurrent wake-ups can't shrink the pool below the floor, and a request arriving while one closes gets a new connection right away.

  • Timing. The idle wait ends at the earlier of the next ping and the idle timeout (changed in review; the first version only checked at ping wake-ups). The ping schedule is unchanged.

  • Name. idle_timeout follows HikariCP and pgbouncer. idle_period, as you suggested, or max_idle_time are fine with me.

  • Hand-out order. Most recently returned first (idle_list.back()), as pgbouncer does by default (added in review). With round-robin, a steady trickle of requests used every connection in turn, so none stayed idle for idle_timeout.
  • Fixes found on the way

    Shrinking to zero (initial_size == 0) exposed that conns_finished_cv was never re-armed, so async_run could complete early; commit 4 fixes it with a regression test. The same latch made a pool with initial_size == 0 that never created a connection impossible to cancel; commit 5 fixes that by starting the latch expired, one line with a test.

    Testing

    Mock-clock unit tests cover the state machine, the close and removal cycle, a request arriving while a connection closes, the timing against pings (an idle timeout shorter and longer than ping_interval, pings disabled, and both disabled), a lost collection notification, the hand-out order, the total floor with connections in use, several surplus connections waking up, a close that times out, cancellation during a close, and the latch. Each commit builds and passes the unit suite on its own. I did not add an integration test; if you want one, I would take two connections, return them, wait, and check that exactly one CONNECTION_ID() is new.

    Not done

  • I did not run the docs build or the integration suite locally. Are there instructions?
  • Developed with Claude Code; I reviewed and tested every commit.

    Thanks!

    Diff: 348 lines (+261 / -87) across 4 files Reviewer: anarthal Review duration: 6456m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.42) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 348 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.350
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #538"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.4% (MEDIUM) · Higher = larger blast radius
    42.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.2% · Safe to merge
    24.2%
    Repository