From a5c3135f53b359bff8878dbafec16c0183d0ab2d Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 20 Dec 2023 01:21:02 -0800 Subject: [PATCH] Handle post_init and unknown terminate crash (#404) Co-authored-by: Simon Unge --- src/ra_server_proc.erl | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ra_server_proc.erl b/src/ra_server_proc.erl index 4740a427..d82f6925 100644 --- a/src/ra_server_proc.erl +++ b/src/ra_server_proc.erl @@ -1006,6 +1006,19 @@ terminate(Reason, StateName, end, _ = ets:delete(ra_metrics, MetricsKey), _ = ets:delete(ra_state, Key), + ok; +%% This occurs if there is a crash in the init callback of the ra_machine, +%% before a state has been built +terminate(Reason, StateName, #{id := Id} = Config) -> + LogId = maps:get(friendly_name, Config, + lists:flatten(io_lib:format("~w", [Id]))), + ?DEBUG("~ts: terminating with ~w in state ~w", + [LogId, Reason, StateName]), + ok; +%% Unknown reason for termination +terminate(Reason, StateName, State) -> + ?DEBUG("Terminating with ~w in state ~w with state ~w", + [Reason, StateName, State]), ok. code_change(_OldVsn, StateName, State, _Extra) ->