fix: stop pool max-lifetime retirement from killing in-flight queries - #653
Merged
Conversation
Bun 1.3.14 retires a pooled connection the instant maxLifetime elapses, mid-query included (oven-sh/bun#30646, fix unmerged), failing healthy queries with ERR_POSTGRES_LIFETIME_TIMEOUT on a 30-minute cadence. In production this killed better-auth session reads, returning 500 on every authed route, and failed cron ingest and worker sync jobs. Disable age-based retirement; idleTimeout still reaps idle connections. Fixes #620 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013BQkcrAZNXz7au7KkkT7JV
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.
Bun 1.3.14's pool fails a connection the instant
maxLifetimeelapses —onMaxLifetimeTimeoutnever checks for a query in flight — so healthy queries die withERR_POSTGRES_LIFETIME_TIMEOUTand nothing retries them (oven-sh/bun#30646; fix oven-sh/bun#30648 unmerged, no release changes this). With our 1800s lifetime this killed the better-auth session read on a ~30-minute cadence (500 on every authed route) plus cron ingest and worker jobs; Loki shows bursts clustered at :02/:32, matching connection cohorts aging out together. Setting the lifetime to 0 removes the failure mode entirely; idleTimeout still reaps idle connections, so nothing accumulates.ERR_POSTGRES_LIFETIME_TIMEOUT: unsafe for non-idempotent writes (a statement can commit server-side before the socket dies), and reads-only classification has no central choke point.maxLifetimekills an in-flightpg_sleep), pins the shipped pool config at 0 (red before, green after), and shows 0 leaves in-flight queries untouched.Note: the same driver race exists for
idleTimeout(~2k worker job failures/day asIdle timeout reached after 30s) — left for a follow-up since disabling it changes pool capacity behavior.Fixes #620
🤖 Generated with Claude Code
https://claude.ai/code/session_013BQkcrAZNXz7au7KkkT7JV