Skip to content

Commit 331df56

Browse files
whatyouhidezmstone
andauthored
Handle offset commits during a connection-down window (#670)
* Handle offset commits during a connection-down window Co-authored-by: zmstone <zmstone@gmail.com>
1 parent ef086a2 commit 331df56

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
- 4.5.8
4+
- Fix a consumer-group coordinator crash when offset commits race with
5+
recovery from a lost broker connection.
6+
37
- 4.5.7
48
- Replace old `catch` expressions with `try ... catch` for OTP-29.
59

src/brod_group_coordinator.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,8 @@ do_commit_offsets_(#state{acked_offsets = []} = State) ->
803803
{ok, State};
804804
do_commit_offsets_(#state{offset_commit_policy = consumer_managed} = State) ->
805805
{ok, State};
806+
do_commit_offsets_(#state{connection = Connection}) when not is_pid(Connection) ->
807+
erlang:throw({connection_down, noproc});
806808
do_commit_offsets_(#state{ groupId = GroupId
807809
, memberId = MemberId
808810
, generationId = GenerationId

test/brod_group_coordinator_SUITE.erl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
%% Test cases
4040
-export([ t_acks_during_revoke/1
41+
, t_commit_offsets_without_connection/1
4142
, t_update_topics_triggers_rebalance/1
4243
, t_offset_fetch_minus_one_falls_back_to_reset_policy/1
4344
, t_member_id_required_dynamic_member/1
@@ -134,6 +135,33 @@ t_acks_during_revoke(Config) when is_list(Config) ->
134135

135136
ok.
136137

138+
t_commit_offsets_without_connection(Config) when is_list(Config) ->
139+
GroupId = list_to_binary(
140+
"brod-grp-coord-no-connection-" ++
141+
integer_to_list(erlang:unique_integer([positive]))),
142+
{ok, CoordinatorPid} =
143+
brod_group_coordinator:start_link(?CLIENT_ID, GroupId, [?TOPIC],
144+
_Config = [], ?MODULE, {self(), 1}),
145+
unlink(CoordinatorPid),
146+
try
147+
?assert_receive({assignments_revoked, 1}, ok),
148+
CoordinatorPid ! continue,
149+
?assert_receive({assignments_received, 1, _, _}, ok),
150+
%% `connection` is the seventh state record field, at tuple index 8.
151+
_ = sys:replace_state(
152+
CoordinatorPid, fun(State) -> setelement(8, State, undefined) end),
153+
?assertEqual(
154+
{error, {connection_down, noproc}},
155+
brod_group_coordinator:commit_offsets(
156+
CoordinatorPid, [{{?TOPIC, ?PARTITION}, 0}])),
157+
?assert(is_process_alive(CoordinatorPid)),
158+
?assert_receive({assignments_revoked, 1}, ok)
159+
after
160+
MRef = erlang:monitor(process, CoordinatorPid),
161+
exit(CoordinatorPid, kill),
162+
receive {'DOWN', MRef, process, CoordinatorPid, _} -> ok end
163+
end.
164+
137165
t_update_topics_triggers_rebalance(Config) when is_list(Config) ->
138166
{ok, GroupCoordinatorPid} =
139167
brod_group_coordinator:start_link(?CLIENT_ID, ?GROUP, [?TOPIC],

0 commit comments

Comments
 (0)