Adds pool_params::idle_timeout, closing idle connections above initial_size #538
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
anarthal
Closes #499.
What it does
Adds
pool_params::idle_timeout, zero by default (disabled). A connection that has been idle foridle_timeoutis closed and removed from the pool, as long as the pool has more thaninitial_sizeconnections in any state; the pool never shrinks belowinitial_size. This works with pings disabled too. The node sends a clean QUIT throughasync_close, bounded by the newclose_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
initial_sizebounds 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.idle_timeoutfollows HikariCP and pgbouncer.idle_period, as you suggested, ormax_idle_timeare fine with me.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 foridle_timeout.Fixes found on the way
Shrinking to zero (
initial_size == 0) exposed thatconns_finished_cvwas never re-armed, soasync_runcould complete early; commit 4 fixes it with a regression test. The same latch made a pool withinitial_size == 0that 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 oneCONNECTION_ID()is new.Not done
Developed with Claude Code; I reviewed and tested every commit.
Thanks!