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 coordinator process exiting due to heartbeat race #578

Merged
merged 1 commit into from
May 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/brod_group_coordinator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,11 @@ stabilize(#state{ rejoin_delay_seconds = RejoinDelaySeconds
State3 = State2#state{is_in_group = false},

%$ 4. Clean up state based on the last failure reason
State = maybe_reset_member_id(State3, Reason),
State4 = maybe_reset_member_id(State3, Reason),

%% 5. Clean up ongoing heartbeat request ref if connection
%% was closed
State = maybe_reset_hb_ref(State4, Reason),

%% 5. ensure we have a connection to the (maybe new) group coordinator
F1 = fun discover_coordinator/1,
Expand Down Expand Up @@ -591,6 +595,15 @@ should_reset_member_id({connection_down, _Reason}) ->
should_reset_member_id(_) ->
false.

%% When connection goes down while waiting for heartbeat
%% response, the response will never be received.
%% Reset heartbeat ref to let new heartbeat request to
%% be sent over new connection.
maybe_reset_hb_ref(State, {connection_down, _Reason}) ->
State#state{hb_ref = ?undef};
maybe_reset_hb_ref(State, _) ->
State.

-spec join_group(state()) -> {ok, state()}.
join_group(#state{ groupId = GroupId
, memberId = MemberId0
Expand Down
Loading