Survive a multiplexing connection pooler - #86
Conversation
Serverless instances each opened their own pool of ten connections while Supabase allows fifteen in session mode, so page loads failed with EMAXCONNSESSION once a couple of instances were warm. Two causes. The pool was only memoised on globalThis outside production, so every bundle that evaluated this module built another pool. Route handlers and the server renderer are separate bundles, so one instance held two pools. Memoise unconditionally. A transaction pooler multiplexes many clients onto one backend connection, and Bun names prepared statements after the query text, so concurrent clients collide on the name. Detect that pooler by its port and let the driver send unnamed statements instead.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 10 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: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughChangesDatabase pooler support
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant DATABASE_URL
participant multiplexesConnections
participant pool
DATABASE_URL->>multiplexesConnections: provide connection URL
multiplexesConnections-->>pool: return transaction-pooler status
pool->>pool: set prepare option
pool->>pool: assign globalForDb.orbitPool
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/db/src/client.test.ts (1)
6-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover pool configuration, not only detection.
These tests verify
multiplexesConnections, but not the changed integration: port6543must create a pool withprepare: false, other URLs must keep preparation enabled, and the global cache must not reuse incompatible configuration. Extract the pool factory/options if needed to test these contracts without opening a database connection.🤖 Prompt for 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. In `@packages/db/src/client.test.ts` around lines 6 - 40, Extend the tests beyond multiplexesConnections to cover the pool-creation integration: verify port 6543 produces pool options with prepare disabled, while other connection URLs retain preparation enabled. Also verify the global pool cache does not reuse a pool created with incompatible preparation settings; extract the pool factory or options builder if necessary so these contracts can be tested without opening a database connection.
🤖 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/db/src/client.ts`:
- Around line 34-42: Update the global pool lookup and assignment around the
orbitPool initialization so caching occurs only in production, preventing
development and test imports from reusing stale connection configuration.
Preserve creating a fresh SQL pool with the current connectionString,
poolMax.data, and multiplexesConnections(connectionString) settings when the
production guard is not active.
---
Nitpick comments:
In `@packages/db/src/client.test.ts`:
- Around line 6-40: Extend the tests beyond multiplexesConnections to cover the
pool-creation integration: verify port 6543 produces pool options with prepare
disabled, while other connection URLs retain preparation enabled. Also verify
the global pool cache does not reuse a pool created with incompatible
preparation settings; extract the pool factory or options builder if necessary
so these contracts can be tested without opening a database connection.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e285005b-9629-4dad-8429-0bf40888e861
📒 Files selected for processing (2)
packages/db/src/client.test.tspackages/db/src/client.ts
Memoising unconditionally meant a later import could be handed a pool built from a different url, size, or prepare mode. Key the entry so a pool is only reused when every option matches, which keeps one pool per configuration in a next dev process and across the separate route and renderer bundles in production.
There was a problem hiding this comment.
pulkitxm has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Memoise the database pool in production and disable named prepared statements behind a transaction pooler.