Repository navigation
Support :max_lifetime, :idle_limit, and :checkout_retries DBConnection options - #329
Open
eltonplima wants to merge 2 commits into
Open
eltonplima wants to merge 2 commits into
eltonplima wants to merge 2 commits into
Conversation
Add three DBConnection options that were previously silently dropped by the @postgrex_connection_opts allowlist in EventStore.Config.postgrex_opts/2. :idle_limit (DBConnection v2.4.3) caps the number of connections disconnected during a single idle ping interval, preventing thundering-herd reconnects on large pools. :checkout_retries (DBConnection v2.9.0) retries a pool checkout on transient queue timeouts instead of immediately returning an error, improving resilience under burst traffic. :max_lifetime (DBConnection v2.10.0) enables native per-connection recycling by disconnecting connections that exceed a configurable age. This is intentionally restricted to the main connection pool via a separate @main_pool_only_opts list and is NOT forwarded to default_postgrex_opts, which feeds both the advisory locks pool and the notifications pool: - Advisory lock connections use backoff_type: :stop so that a lost connection terminates the process, signalling to subscribers that the distributed lock has been released. If :max_lifetime were forwarded here, each recycle cycle would terminate the advisory lock process permanently, breaking distributed subscription assignment. - Notification connections hold LISTEN registrations that would be silently dropped on each recycle cycle, causing missed events until the subscription reconnects and re-registers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
eltonplima
marked this pull request as ready for review
September 28, 2026 15:20
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
eltonplima
force-pushed
the
add-missing-dbconnection-opts
branch
from
September 29, 2026 09:10
ced1698 to
672fd0b
Compare
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.
Summary
Three
DBConnectionoptions added after EventStore's@postgrex_connection_optsallowlist was last updated are silently dropped when configuring an event store. This PR adds them.:idle_limit(DBConnection v2.4.3, Nov 2022)Caps how many idle connections are disconnected during a single ping interval. Without this option, all idle connections in a large pool can be pinged and recycled simultaneously, causing a thundering-herd reconnect spike.
Added to
@postgrex_connection_opts— safe for all pools.:checkout_retries(DBConnection v2.9.0, Jan 2026)Retries a pool checkout when the queue times out, rather than immediately returning an error. Improves resilience under burst traffic.
Added to
@postgrex_connection_opts— safe for all pools.:max_lifetime(DBConnection v2.10.0, Apr 2026)Recycles connections that exceed a configurable age (supports a
min..maxrange for jitter). This is the idiomatic way to prevent long-lived connections from accumulating stale state or hitting infrastructure-level idle timeouts (e.g. RDS Proxy).Intentionally restricted to the main pool only via a new
@main_pool_only_optslist. It must not flow throughdefault_postgrex_opts/1, which is shared by two other pools:backoff_type: :stop): this pool is deliberately configured to stop — not restart — when its connection drops, so that subscriptions can detect the lost distributed lock. If:max_lifetimewere forwarded here, each recycle cycle would permanently terminate the advisory lock process, breaking distributed subscription assignment.LISTENregistrations that are dropped on disconnect. Recycling would silently miss events until the subscription reconnects and re-registers.postgrex_opts/2(the main pool) uses@postgrex_connection_opts ++ @main_pool_only_optsso:max_lifetimeis available there, whiledefault_postgrex_opts/1continues to use only@postgrex_connection_opts.Checklist
mix formatpasses