Skip to content

Commit 1568a0e

Browse files
committed
khepri_cluster: Log an error if trigger_election/2 fails during start
[Why] The `fail_to_start_with_bad_ra_server_config` test case wants to start a store with a invalid configuration. This causes the Ra server to crash during init. Its supervisor restarts it but eventually aborts. If `trigger_election/2` happens to be executed after the last restart attempt from the supervisor, it will get a `noproc` exception. [How] We still raise this exception but we log an error. While here, don't match the return value of `trigger_election/2` because it's always `ok`.
1 parent 564d584 commit 1568a0e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/khepri_cluster.erl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,17 @@ ensure_server_started_locked(
390390
[StoreId, RaSystem]),
391391
case do_start_server(RaSystem, RaServerConfig1) of
392392
ok ->
393-
ok = trigger_election(RaServerConfig1, Timeout),
394-
{ok, StoreId};
393+
try
394+
trigger_election(RaServerConfig1, Timeout),
395+
{ok, StoreId}
396+
catch
397+
Class:Reason:Stacktrace ->
398+
?LOG_ERROR(
399+
"Failed to trigger election on the freshly "
400+
"started Ra server for store \"~s\"::~n~p",
401+
[StoreId, Reason]),
402+
erlang:raise(Class, Reason, Stacktrace)
403+
end;
395404
Error ->
396405
Error
397406
end;
@@ -858,7 +867,7 @@ do_join_locked(StoreId, ThisMember, RemoteNode, Timeout) ->
858867
%% standalone (after a reset) and needs an election to be in a
859868
%% working state again. We don't care about the result at this
860869
%% point.
861-
_ = trigger_election(ThisMember, Timeout1),
870+
trigger_election(ThisMember, Timeout1),
862871
case Error of
863872
{timeout, _} -> {error, timeout};
864873
{error, _} -> Error

0 commit comments

Comments
 (0)