refactor(emqx_machine_terminator): future-proof try-catch
Ensure exceptions in emqx_machine:stop_apps/0 is caught and call init:stop/0 in the after clause
This commit is contained in:
parent
044e084698
commit
81c9dcb6ae
|
@ -27,6 +27,8 @@
|
||||||
handle_cast/2, handle_call/3, handle_info/2,
|
handle_cast/2, handle_call/3, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
|
-include_lib("emqx/include/logger.hrl").
|
||||||
|
|
||||||
-define(TERMINATOR, ?MODULE).
|
-define(TERMINATOR, ?MODULE).
|
||||||
-define(DO_IT, graceful_shutdown).
|
-define(DO_IT, graceful_shutdown).
|
||||||
|
|
||||||
|
@ -62,8 +64,20 @@ init(_) ->
|
||||||
{ok, #{}}.
|
{ok, #{}}.
|
||||||
|
|
||||||
handle_info(?DO_IT, State) ->
|
handle_info(?DO_IT, State) ->
|
||||||
ok = emqx_machine:stop_apps(normal),
|
try
|
||||||
init:stop(),
|
emqx_machine:stop_apps(normal)
|
||||||
|
catch
|
||||||
|
C : E : St ->
|
||||||
|
Apps = [element(1, A) || A <- application:which_applications()],
|
||||||
|
?SLOG(error, #{msg => "failed_to_stop_apps",
|
||||||
|
exception => C,
|
||||||
|
reason => E,
|
||||||
|
stacktrace => St,
|
||||||
|
remaining_apps => Apps
|
||||||
|
})
|
||||||
|
after
|
||||||
|
init:stop()
|
||||||
|
end,
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info(_, State) ->
|
handle_info(_, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
Loading…
Reference in New Issue