feat(common): implement LRU connection cache and circuit breakers - #370
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 43 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughChangesConnection resource resilience
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Client
participant getConnection
participant circuitBreakers
participant registry
participant Database
Client->>getConnection: request project connection
getConnection->>circuitBreakers: check breaker state
circuitBreakers-->>getConnection: allow or return 503
getConnection->>registry: read or create cached connection
getConnection->>Database: establish connection
Database-->>getConnection: success or failure
getConnection->>circuitBreakers: reset or record failure
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/common/src/utils/connection.manager.js`:
- Around line 37-40: Update the circuit-breaker transition in the half-open
branch to synchronously mark a probe as in flight before allowing the retry, and
reject concurrent callers with 503 while that marker is set. Ensure the marker
is cleared only by the probe’s success or failure handling, using the relevant
connection-manager callback paths, rather than clearing openUntil alone.
In `@packages/common/src/utils/registry.js`:
- Around line 70-71: Replace the unbounded circuitBreakers Map with a capped or
TTL-backed registry so entries for inactive projects are evicted while active
breaker state remains available. Update the registry access logic that uses
circuitBreakers to enforce the chosen size or expiration policy without changing
circuit-breaker behavior.
- Around line 55-59: Prevent stale asynchronous connection events from removing
or affecting replacement entries. In packages/common/src/utils/registry.js lines
55-59, expose a deleteIfCurrent(key, connection) operation that removes an entry
only when its value matches the supplied connection. In
packages/common/src/utils/connection.manager.js lines 131-145, update lifecycle
handlers to use this identity-checked removal and record breaker failures only
when removal succeeds; ignore events from evicted or superseded connections.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a78a9a65-3c57-4c74-8d36-ab290b85aa68
📒 Files selected for processing (2)
packages/common/src/utils/connection.manager.jspackages/common/src/utils/registry.js
Implemented LRU Cache for Database Connection Caching.
Summary by CodeRabbit