Skip to content

Add max_requests client option - #143

Merged
lpgauth merged 1 commit into
masterfrom
max-requests
Aug 23, 2026
Merged

Add max_requests client option#143
lpgauth merged 1 commit into
masterfrom
max-requests

Conversation

@lpgauth

@lpgauth lpgauth commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a max_requests client option (pos_integer() | infinity, default infinity) that limits how many requests a connection handles before it is recycled, as requested in #69.

When the cap is reached, the server is disabled in the pool so no new requests are routed to it, in-flight requests drain normally, then the socket is closed and reconnected immediately (skipping the reconnect backoff, since the connection was healthy). Reconnecting goes through inet:getaddrs/2, so DNS is re-resolved on every recycle — enabling periodic rebalancing across DNS-based load balancers.

  • Recycling is checked after each send, after processing replies, and after sweep expiry, so the drain converges even for noop-only or timed-out tails.
  • requests_left is reset on every successful connect; error-driven reconnects are unaffected.
  • Documented in the README client_options table and covered by a new eunit test that asserts the socket is replaced after max_requests calls while requests keep succeeding.

Closes #69

Limit the number of requests a connection handles before it is
recycled. When the cap is reached the server is disabled in the
pool so no new requests are routed to it, in-flight requests drain
normally, then the socket is closed and reconnected immediately.
Reconnecting re-resolves DNS, which allows periodic rebalancing
across DNS-based load balancers.

Defaults to infinity, preserving existing behavior.
@lpgauth
lpgauth merged commit 0431718 into master Aug 23, 2026
4 checks passed
@lpgauth
lpgauth deleted the max-requests branch August 23, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add max_requests client option

1 participant