From 7c34c8a8b1fb51f32b90df146e2423585e4a5791 Mon Sep 17 00:00:00 2001 From: Zhongwen Deng Date: Mon, 9 May 2022 23:03:52 +0800 Subject: [PATCH] fix: retry if init_disaptch failed --- apps/emqx_conf/src/emqx_conf_schema.erl | 1 + .../src/emqx_dashboard_listener.erl | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/apps/emqx_conf/src/emqx_conf_schema.erl b/apps/emqx_conf/src/emqx_conf_schema.erl index 7ab815d9a..aedfe6a25 100644 --- a/apps/emqx_conf/src/emqx_conf_schema.erl +++ b/apps/emqx_conf/src/emqx_conf_schema.erl @@ -443,6 +443,7 @@ fields("node") -> #{ mapping => "vm_args.-env ERL_CRASH_DUMP", desc => ?DESC(node_crash_dump_file), + default => "log/erl_crash.dump", 'readOnly' => true } )}, diff --git a/apps/emqx_dashboard/src/emqx_dashboard_listener.erl b/apps/emqx_dashboard/src/emqx_dashboard_listener.erl index b649575ed..8bd5a4eb3 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard_listener.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard_listener.erl @@ -38,7 +38,7 @@ ]). is_ready(Timeout) -> - ready =:= gen_server:call(?MODULE, get_state, Timeout). + ready =:= gen_server:call(?MODULE, is_ready, Timeout). start_link() -> gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). @@ -49,10 +49,13 @@ init([]) -> {ok, undefined, {continue, regenerate_dispatch}}. handle_continue(regenerate_dispatch, _State) -> - regenerate_minirest_dispatch(), - {noreply, ready, hibernate}. + NewState = regenerate_minirest_dispatch(), + {noreply, NewState, hibernate}. -handle_call(get_state, _From, State) -> +handle_call(is_ready, _From, retry) -> + NewState = regenerate_minirest_dispatch(), + {reply, NewState, NewState, hibernate}; +handle_call(is_ready, _From, State) -> {reply, State, State, hibernate}; handle_call(_Request, _From, State) -> {reply, ok, State, hibernate}. @@ -63,8 +66,8 @@ handle_cast(_Request, State) -> handle_info({update_listeners, OldListeners, NewListeners}, _State) -> ok = emqx_dashboard:stop_listeners(OldListeners), ok = emqx_dashboard:start_listeners(NewListeners), - regenerate_minirest_dispatch(), - {noreply, ready, hibernate}; + NewState = regenerate_minirest_dispatch(), + {noreply, NewState, hibernate}; handle_info(_Info, State) -> {noreply, State, hibernate}. @@ -84,9 +87,17 @@ regenerate_minirest_dispatch() -> minirest:update_dispatch(element(1, Listener)) end, emqx_dashboard:list_listeners() - ) + ), + ready catch - _:_ -> ok + T:E:S -> + ?SLOG(error, #{ + msg => "regenerate_minirest_dispatch_failed", + reason => E, + type => T, + stacktrace => S + }), + retry after emqx_dashboard:clear_i18n() end.