⚡️ perf(database): add optional statement_timeout to server DB connections#15445
Merged
Conversation
…tions Long-running queries (e.g. an insert stuck for 700s on lock contention) could block indefinitely because Postgres' statement_timeout defaults to 0 (no limit) and neither the node nor neon pool configured one. Add an optional DATABASE_STATEMENT_TIMEOUT env (milliseconds, no default) applied to both NodePool and NeonPool as statement_timeout and idle_in_transaction_session_timeout, so Postgres aborts a stuck statement or idle transaction on the server side. Unset keeps the previous behavior. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## canary #15445 +/- ##
===========================================
- Coverage 89.70% 70.88% -18.82%
===========================================
Files 862 3223 +2361
Lines 105731 319682 +213951
Branches 10246 34782 +24536
===========================================
+ Hits 94841 226593 +131752
- Misses 10714 92913 +82199
Partials 176 176
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This was referenced Jun 9, 2026
Closed
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💻 Change Type
🔗 Related Issue
🔀 Description of Change
Long-running queries (an
insertobserved stuck for 700s under lock contention) could block indefinitely, because Postgres'statement_timeoutdefaults to0(no limit) and neither thenode(pg) nor theneon(@neondatabase/serverless) pool configured any timeout.This adds an optional
DATABASE_STATEMENT_TIMEOUTenv (in milliseconds, no default — unset keeps the previous behavior), applied to bothNodePoolandNeonPool:statement_timeout— Postgres aborts any single statement exceeding the limit on the server side, actually freeing the backend (not just a client-side reject).idle_in_transaction_session_timeout— kills a transaction left idle past the limit, so a stuck transaction can't keep holding row locks.Both drivers natively support these keys in their pool config (verified against their type defs /
pgclient implementation). When the env is unset, the timeout keys are omitted entirely, preserving Postgres defaults..env.exampledocuments the new variable (suggested300000= 300s).🧪 How to Test
Set
DATABASE_STATEMENT_TIMEOUT=5000, run a query that exceeds 5s (e.g.SELECT pg_sleep(10)), and confirm Postgres aborts it withcanceling statement due to statement timeout. With the env unset, behavior is unchanged.📝 Additional Information
statement_timeoutis server-side termination (the robust knob for "kill blocking queries"); a client-sidequery_timeoutwas intentionally not added, since it only rejects the JS promise while the statement can keep running on the server.🤖 Generated with Claude Code