Repository navigation
LVT-382: Retry connections while sleeping Postgres wakes - #134
Conversation
The Railway preview returned ETIMEDOUT on its first database-backed request after sleep. Retry only transient pool connection acquisition failures, never SQL execution, and retain process-owned pool disposal across reconnects. Bound retries and preserve authentication and statement failures.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Lovat AI reviewStatus: completed · Model: Reviewed commit: Critical: 0 · High: 1 · Medium: 0 · Low: 0 Overall assessmentThe retry helper itself is well-bounded and preserves the original error, but the adapter integration is unsafe: every connect() call constructs a brand-new pg Pool (up to 10 connections each) that nothing ever disposes, and the pool created by the superclass is orphaned. Under Prisma, connect() is invoked per connection slot, so this can multiply Postgres connections instead of retrying them. The pool.connect monkey-patch also retries pool-saturation timeouts, which stacks duplicate waiters. FindingsHigh (1)
Review details
Limitations
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0418a2eba8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Lovat AI review: 1 new finding(s) at 7ee53d803def1f5d989a684a70f910a95fb0a4df.
The persistent Lovat AI review comment contains the latest complete result.
packages/db/src/connection-retry.ts:84— ConnectionRetryAdapter.connect() creates a new undisposed Pool on every connect call (PERFORMANCE· confidence 0.75)
jackshim415
left a comment
There was a problem hiding this comment.
Final review: wrapped pg-pool timeouts are covered, retries occur only before a SQL connection is acquired, and statement/transaction execution is not replayed. PostgreSQL integration tests verify writes, rollback, transactions and zero owned connections after disconnect/reconnect. Required CI, Server, Worker and cross-app contracts passed. Three real Railway cold probes succeeded in 1,405 / 1,394 / 1,366 ms while recovering ETIMEDOUT and ECONNREFUSED. The pool-leak finding was checked against the installed adapter lifecycle and measured pg_stat_activity disposal test and is not applicable. Ready for the authorized Cron cutover.
What changed
The isolated Railway sleep test returned HTTP 500 with
ETIMEDOUTon the first database-backed request; the next request succeeded. Add two bounded retries for transient PostgreSQL connection acquisition failures while the service wakes.Only obtaining a connection is retried. SQL statements, writes and transactions are never replayed; authentication and statement errors fail immediately. Each Prisma connection creates an owned pool which disconnects fully and can be recreated on a later query, preserving finite Worker execution.
Areas affected
Contracts and data
Verification
Deployment
No migrations or new dependencies. Production Cron remains staged until the cold-query check passes. Only Postgres needs Serverless sleeping; Worker uses normal Cron execution. Related: LVT-382; PR #133 adds event-aware scheduled runs.