Skip to content

Commit

Permalink
Interrupt other waiting calls in mongoose_cluster_id
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Nov 16, 2023
1 parent 7213213 commit 1cfdada
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/mongoose_cluster_id.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ start() ->
%% the starting procedure
wait_for_any_backend(Backend, IntBackend) ->
Alias = erlang:alias([reply]),
[wait_for_backend_promise(B, Alias) || B <- lists:sort([Backend, IntBackend])],
wait_for_first_reply(Alias).
Pids = lists:append([wait_for_backend_promise(B, Alias) || B <- lists:sort([Backend, IntBackend])]),
wait_for_first_reply(Alias),
%% Interrupt other waiting calls to reduce the logging noise
[erlang:exit(Pid, normal) || Pid <- Pids],
ok.

wait_for_first_reply(Alias) ->
receive
Expand All @@ -63,19 +66,20 @@ wait_for_first_reply(Alias) ->
end.

wait_for_backend_promise(mnesia, Alias) ->
Alias ! {ready, Alias};
Alias ! {ready, Alias},
[];
wait_for_backend_promise(cets, Alias) ->
spawn(fun() ->
[spawn(fun() ->

Check warning on line 72 in src/mongoose_cluster_id.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cluster_id.erl#L72

Added line #L72 was not covered by tests
%% We have to do it, because we want to read from across the cluster
%% in the start/0 function.
ok = cets_discovery:wait_for_ready(mongoose_cets_discovery, infinity),
Alias ! {ready, Alias}

Check warning on line 76 in src/mongoose_cluster_id.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cluster_id.erl#L75-L76

Added lines #L75 - L76 were not covered by tests
end);
end)];
wait_for_backend_promise(rdbms, Alias) ->
spawn(fun() ->
[spawn(fun() ->
wait_for_rdbms(),
Alias ! {ready, Alias}

Check warning on line 81 in src/mongoose_cluster_id.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cluster_id.erl#L79-L81

Added lines #L79 - L81 were not covered by tests
end).
end)].

wait_for_rdbms() ->
case get_backend_cluster_id(rdbms) of

Check warning on line 85 in src/mongoose_cluster_id.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cluster_id.erl#L85

Added line #L85 was not covered by tests
Expand Down

0 comments on commit 1cfdada

Please sign in to comment.