Skip to content

Commit

Permalink
fix: /listeners API crash when some nodes still in init configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwencool committed Sep 19, 2022
1 parent e8e2393 commit 386110a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
## Bug fixes

* 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

Expand Down
18 changes: 12 additions & 6 deletions apps/emqx/src/emqx_listeners.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ format_list(Listener) ->
].

do_list_raw() ->
Key = <<"listeners">>,
Raw = emqx_config:get_raw([Key], #{}),
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).
%% GET /listeners from other nodes returns [] when init config is not loaded.
case emqx_app:get_init_config_load_done() of
true ->
Key = <<"listeners">>,
Raw = emqx_config:get_raw([Key], #{}),
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}) ->
Type = binary_to_atom(Type0),
Expand Down
8 changes: 4 additions & 4 deletions apps/emqx_conf/src/emqx_conf_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ copy_override_conf_from_core_node() ->
_ ->
[{ok, Info} | _] = lists:sort(fun conf_sort/2, Ready),
#{node := Node, conf := RawOverrideConf, tnx_id := TnxId} = Info,
Msg = #{
?SLOG(debug, #{
msg => "copy_overide_conf_from_core_node_success",
node => Node
},
?SLOG(debug, Msg),
node => Node,
envs => application:get_all_env(emqx)
}),
ok = emqx_config:save_to_override_conf(
RawOverrideConf,
#{override_to => cluster}
Expand Down

0 comments on commit 386110a

Please sign in to comment.