Skip to content

fix: reconnect backoff#43

Merged
JimMoen merged 8 commits into
branch-0.7.xfrom
fix/reconnect-backoff
Mar 16, 2026
Merged

fix: reconnect backoff#43
JimMoen merged 8 commits into
branch-0.7.xfrom
fix/reconnect-backoff

Conversation

@JimMoen

@JimMoen JimMoen commented Mar 13, 2026

Copy link
Copy Markdown
Member

No description provided.

JimMoen added 8 commits March 13, 2026 11:02
When start_connection fails, the reconnect scheduling relies on the
EXIT signal from the failed eredis process (gen_server:start_link
establishes a link before init runs, so {stop, Reason} always
produces an EXIT). This EXIT handler uses a fixed 2s interval
regardless of how many consecutive failures have occurred.

Add explicit reconnect scheduling with exponential backoff in the
reconnect handler itself: 2s, 4s, 4s, 8s, 8s, 16s, 16s, ... capped
at 4096s (~1.13h). Each interval is used twice before doubling to
avoid overly aggressive growth.

Suppress the duplicate reconnect from the EXIT handler when a
backoff-scheduled reconnect is already pending (conn=undefined case),
so the backoff delay is not bypassed.

Reset the backoff counter on successful connection or when an
established connection goes down (normal disconnection).
In get_cluster_slots, when the CLUSTER SLOTS command returns 'ERR
unknown command' or 'ERR cluster support disabled', the temporary
eredis connection was not being stopped before falling through to
get_cluster_slots_from_single_node. This leaked an eredis process
each time reload_slots_map was triggered for a non-cluster Redis
instance.

Add eredis:stop(Connection) in both error branches to match the
cleanup done in the success and other error paths.
@JimMoen JimMoen merged commit caeeed7 into branch-0.7.x Mar 16, 2026
1 check passed
@JimMoen JimMoen deleted the fix/reconnect-backoff branch March 16, 2026 04:58
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.

2 participants