fix: reconnect backoff#43
Merged
Merged
Conversation
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.
hjianbo
approved these changes
Mar 13, 2026
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.
No description provided.