fix: /listeners API crash when some nodes still in init configuration

This commit is contained in:
Zhongwen Deng 2022-09-19 15:05:06 +08:00
parent e8e23938a2
commit 386110ae1e
3 changed files with 17 additions and 10 deletions

View File

@ -7,6 +7,7 @@
## Bug fixes ## Bug fixes
* Check ACLs for last will testament topic before publishing the message. [#8930](https://github.com/emqx/emqx/pull/8930) * Check ACLs for last will testament topic before publishing the message. [#8930](https://github.com/emqx/emqx/pull/8930)
* Fix GET /listeners API crash When some nodes still in initial configuration. [#9002](https://github.com/emqx/emqx/pull/9002)
# 5.0.8 # 5.0.8

View File

@ -87,12 +87,18 @@ format_list(Listener) ->
]. ].
do_list_raw() -> do_list_raw() ->
Key = <<"listeners">>, %% GET /listeners from other nodes returns [] when init config is not loaded.
Raw = emqx_config:get_raw([Key], #{}), case emqx_app:get_init_config_load_done() of
SchemaMod = emqx_config:get_schema_mod(Key), true ->
#{Key := RawWithDefault} = emqx_config:fill_defaults(SchemaMod, #{Key => Raw}, #{}), Key = <<"listeners">>,
Listeners = maps:to_list(RawWithDefault), Raw = emqx_config:get_raw([Key], #{}),
lists:flatmap(fun format_raw_listeners/1, Listeners). SchemaMod = emqx_config:get_schema_mod(Key),
#{Key := RawWithDefault} = emqx_config:fill_defaults(SchemaMod, #{Key => Raw}, #{}),
Listeners = maps:to_list(RawWithDefault),
lists:flatmap(fun format_raw_listeners/1, Listeners);
false ->
[]
end.
format_raw_listeners({Type0, Conf}) -> format_raw_listeners({Type0, Conf}) ->
Type = binary_to_atom(Type0), Type = binary_to_atom(Type0),

View File

@ -152,11 +152,11 @@ copy_override_conf_from_core_node() ->
_ -> _ ->
[{ok, Info} | _] = lists:sort(fun conf_sort/2, Ready), [{ok, Info} | _] = lists:sort(fun conf_sort/2, Ready),
#{node := Node, conf := RawOverrideConf, tnx_id := TnxId} = Info, #{node := Node, conf := RawOverrideConf, tnx_id := TnxId} = Info,
Msg = #{ ?SLOG(debug, #{
msg => "copy_overide_conf_from_core_node_success", msg => "copy_overide_conf_from_core_node_success",
node => Node node => Node,
}, envs => application:get_all_env(emqx)
?SLOG(debug, Msg), }),
ok = emqx_config:save_to_override_conf( ok = emqx_config:save_to_override_conf(
RawOverrideConf, RawOverrideConf,
#{override_to => cluster} #{override_to => cluster}