Skip to content

Commit 84607b7

Browse files
authored
Merge pull request #12853 from rabbitmq/mirrored-sup-retry-update-after-db-timeout
mirrored_supervisor: Catch timeout from Khepri in `hanlde_info/2`
2 parents 84449a4 + 4621fe7 commit 84607b7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

deps/rabbit/src/mirrored_supervisor.erl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ handle_info({'DOWN', _Ref, process, Pid, _Reason},
345345
child_order = ChildOrder}) ->
346346
%% No guarantee pg will have received the DOWN before us.
347347
R = case lists:sort(pg:get_members(Group)) -- [Pid] of
348-
[O | _] -> ChildSpecs = update_all(O, Pid),
348+
[O | _] -> ChildSpecs = retry_update_all(O, Pid),
349349
[start(Delegate, ChildSpec)
350350
|| ChildSpec <- restore_child_order(ChildSpecs,
351351
ChildOrder)];
@@ -428,6 +428,22 @@ check_stop(Group, Delegate, Id) ->
428428

429429
id({Id, _, _, _, _, _}) -> Id.
430430

431+
retry_update_all(O, Pid) ->
432+
retry_update_all(O, Pid, 10000).
433+
434+
retry_update_all(O, Pid, TimeLeft) when TimeLeft > 0 ->
435+
case update_all(O, Pid) of
436+
List when is_list(List) ->
437+
List;
438+
{error, timeout} ->
439+
Sleep = 200,
440+
TimeLeft1 = TimeLeft - Sleep,
441+
timer:sleep(Sleep),
442+
retry_update_all(O, Pid, TimeLeft1)
443+
end;
444+
retry_update_all(O, Pid, _TimeLeft) ->
445+
update_all(O, Pid).
446+
431447
update_all(Overall, OldOverall) ->
432448
rabbit_db_msup:update_all(Overall, OldOverall).
433449

deps/rabbit/src/rabbit_db_msup.erl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ find_mirror_in_khepri(Group, Id) ->
226226
%% update_all().
227227
%% -------------------------------------------------------------------
228228

229-
-spec update_all(Overall, Overall) -> [ChildSpec] when
229+
-spec update_all(Overall, Overall) -> [ChildSpec] | Error when
230230
Overall :: pid(),
231-
ChildSpec :: supervisor2:child_spec().
231+
ChildSpec :: supervisor2:child_spec(),
232+
Error :: {error, any()}.
232233

233234
update_all(Overall, OldOverall) ->
234235
rabbit_khepri:handle_fallback(

0 commit comments

Comments
 (0)