smartconnpool: fix MaxLifetime jitter#20118
Conversation
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
There was a problem hiding this comment.
Pull request overview
Fixes two MaxLifetime jitter edge cases in smartconnpool: avoids uint32 truncation/panic for lifetimes ≥ ~4.29s and treats non-positive values as disabled.
Changes:
- Switch jitter computation to
rand.Int64Nover the fullint64nanosecond range. - Treat
maxLifetime <= 0as disabled. - Add tests covering jitter range and negative-disable behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| go/pools/smartconnpool/pool.go | Use Int64N and guard against non-positive maxLifetime. |
| go/pools/smartconnpool/pool_test.go | Tests for jitter distribution and negative-disable. |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #20118 +/- ##
===========================================
- Coverage 69.67% 52.36% -17.32%
===========================================
Files 1614 8 -1606
Lines 216793 911 -215882
===========================================
- Hits 151044 477 -150567
+ Misses 65749 434 -65315
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Fixes two
smartconnpoolMaxLifetimeedge cases:int64nanosecond duration when adding lifetime jitter. The olduint32cast truncated jitter for lifetimes above roughly 4.29s and could panic on exact multiples of 2^32 ns.MaxLifetimevalues as disabled so a negative duration cannot produce bogus jitter throughrand.Int64N.This is a behavior correction: for long
MaxLifetimevalues, pooled connections can now live anywhere in the intended[MaxLifetime, 2*MaxLifetime)range. Before this PR, those same values effectively lived in a much narrower range close toMaxLifetime, weakening the anti-herd protection and making connection recycling more synchronized.Related Issue(s)
Extracted from #20081.
Backport Justification
This is a small, isolated
smartconnpoolcorrectness fix with no API changes, migrations, or deployment steps. It restores the intendedMaxLifetimejitter behavior and avoids panic/bogus-jitter edge cases for invalid or unlucky duration values.Backporting is useful because released branches can otherwise recycle pooled connections more synchronously than configured for common minute/hour-scale lifetimes. The practical implication is that after this fix, connections may be kept open longer than before, up to nearly
2*MaxLifetime, but that is the documented/intended jitter window rather than a new feature.Checklist
Deployment Notes
No deployment steps required.
AI Disclosure
This PR was written by Codex with direction from Arthur.