Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix next index in retry connect_one #62

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

belltoy
Copy link
Contributor

@belltoy belltoy commented Apr 1, 2024

The list in Erlang is 1-based index, but the rem operator is 0-based. If we want to wrap around the next index of the list via rem operator, we need to turn it back to 0-based. Or else the next index will skip the next one (step 2).

So the next index will be:

%% ZeroBasedIndex = Index - 1,
%% NextZeroBasedIndex = (ZeroBasedIndex + 1 rem Len),
%% NextIndex = NextZeroBasedIndex + 1,

%% NewIndex = (Index -1 + 1) rem Len + 1,
NewIndex = Index rem Len + 1,

@@ -224,7 +224,7 @@ connect_one(Index, Retry, Data, Len) ->
{error, Reason} ->
?LOG_WARNING("~p failed to connect ETCD host: ~p ~p",
[Name, Host, Reason]),
NewIndex = (Index + 1) rem Len + 1,
NewIndex = Index rem Len + 1,
connect_one(NewIndex, Retry - 1, Data, Len)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Catch!

@zhongwencool zhongwencool merged commit 390bc76 into zhongwencool:master Apr 1, 2024
3 checks passed
@belltoy belltoy deleted the fix/retry-index branch April 3, 2024 09:14
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