diff --git a/apps/emqx/src/emqx_config_handler.erl b/apps/emqx/src/emqx_config_handler.erl index d7d63757b..14b9567ee 100644 --- a/apps/emqx/src/emqx_config_handler.erl +++ b/apps/emqx/src/emqx_config_handler.erl @@ -90,6 +90,7 @@ get_raw_cluster_override_conf() -> -spec init(term()) -> {ok, state()}. init(_) -> + process_flag(trap_exit, true), {ok, #{handlers => #{?MOD => ?MODULE}}}. handle_call({add_handler, ConfKeyPath, HandlerName}, _From, State = #{handlers := Handlers}) -> @@ -150,12 +151,8 @@ deep_put_handler2(Key, KeyPath, Handlers, Mod) -> end. handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) -> - try process_update_request(ConfKeyPath, Handlers, UpdateArgs) of - {ok, NewRawConf, OverrideConf, Opts} -> - check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf, - OverrideConf, UpdateArgs, Opts); - {error, Result} -> - {error, Result} + try + do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) catch throw : Reason -> {error, Reason}; @@ -168,6 +165,15 @@ handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) -> {error, config_update_crashed} end. +do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) -> + case process_update_request(ConfKeyPath, Handlers, UpdateArgs) of + {ok, NewRawConf, OverrideConf, Opts} -> + check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf, + OverrideConf, UpdateArgs, Opts); + {error, Result} -> + {error, Result} + end. + process_update_request(ConfKeyPath, _Handlers, {remove, Opts}) -> OldRawConf = emqx_config:get_root_raw(ConfKeyPath), BinKeyPath = bin_path(ConfKeyPath),