fix: add database connection pool configuration#15
Conversation
Configure postgres.js pool with max connections (20, configurable via DB_POOL_MAX), idle timeout (20s), and connect timeout (10s). Defaults had no idle cleanup which could leak connections under load. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Postgres client initialization in the database module now includes a pool configuration object (max from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 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: 1
🤖 Fix all issues with AI agents
In `@src/db/index.ts`:
- Around line 15-20: The current postgres pool config uses
parseInt(process.env.DB_POOL_MAX || "20") which can yield NaN for non-numeric
env values; update the logic around sql creation to validate and default
DB_POOL_MAX: parse DB_POOL_MAX with a radix, check Number.isFinite and >0, and
fall back to 20 when invalid, then pass that validated numeric value to the max
option in the postgres(...) call (refer to the sql export and the parseInt usage
for where to change).
🧹 Nitpick comments (1)
src/db/index.ts (1)
16-20: Consider makingidle_timeoutandconnect_timeoutconfigurable too, or document the hardcoded values.
maxis configurable via an env var butidle_timeout(20s) andconnect_timeout(10s) are hardcoded. These may need tuning per environment (e.g., a longer connect timeout behind a VPN/proxy, or a shorter idle timeout in serverless). Even if you keep defaults, adding env var overrides would be consistent with theDB_POOL_MAXpattern.
Use Number.isFinite() check to handle empty string, non-numeric, or negative values for DB_POOL_MAX environment variable. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
max: 20,idle_timeout: 20s,connect_timeout: 10sDB_POOL_MAXenv varidle_timeout: 0), which could leak connections under sustained loadTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit