fix(config): enforce root key name to be a binary (raw config)
Fixes this flaky test: https://github.com/emqx/emqx/actions/runs/5134910014/jobs/9239826162#step:8:1299 ``` =ERROR REPORT==== 31-May-2023::16:16:10.710969 === exception: error key_path: [listeners,tcp,default,authentication] module: emqx_schema msg: change_config_crashed reason: {config_not_found,[<<"listeners">>,<<"tcp">>,<<"default">>, <<"authentication">>]} stacktrace: [{emqx_utils_maps,deep_get,2, [{file, "/__w/emqx/emqx/source/apps/emqx_utils/src/emqx_utils_maps.erl"}, {line,49}]}, {emqx_config_handler,return_change_result,2, [{file, "/__w/emqx/emqx/source/apps/emqx/src/emqx_config_handler.erl"}, {line,456}]}, {emqx_config_handler,check_and_save_configs,7, [{file, "/__w/emqx/emqx/source/apps/emqx/src/emqx_config_handler.erl"}, {line,284}]}, {emqx_config_handler,handle_update_request,4, [{file, "/__w/emqx/emqx/source/apps/emqx/src/emqx_config_handler.erl"}, {line,195}]}, {emqx_config_handler,handle_call,3, [{file, "/__w/emqx/emqx/source/apps/emqx/src/emqx_config_handler.erl"}, {line,124}]}, {gen_server,try_handle_call,4, [{file,"gen_server.erl"},{line,1149}]}, {gen_server,handle_msg,6, [{file,"gen_server.erl"},{line,1178}]}, {proc_lib,init_p_do_apply,3, [{file,"proc_lib.erl"},{line,240}]}] update_req: {{update, {create_authenticator,'tcp:default', #{backend => built_in_database,enable => true, mechanism => password_based}}}, #{rawconf_with_defaults => true}} ``` Which was cause because there were both binary and atom `listeners` keys in the `persistent_term` storage: ```erlang %% persistent_term:get() {{emqx_config,raw_conf,<<"listeners">>}, #{<<"ssl">> => #{<<"default">> => ... ... {{emqx_config,raw_conf,listeners},#{}}, ``` ... and the atom one was winning when fetching the whole config with `emqx_config:get_raw([])`.
This commit is contained in:
parent
b7c72e6cfb
commit
f83f112189
|
@ -299,14 +299,15 @@ get_raw(KeyPath, Default) -> do_get_raw(KeyPath, Default).
|
|||
put_raw(Config) ->
|
||||
maps:fold(
|
||||
fun(RootName, RootV, _) ->
|
||||
?MODULE:put_raw([RootName], RootV)
|
||||
?MODULE:put_raw([bin(RootName)], RootV)
|
||||
end,
|
||||
ok,
|
||||
hocon_maps:ensure_plain(Config)
|
||||
).
|
||||
|
||||
-spec put_raw(emqx_utils_maps:config_key_path(), term()) -> ok.
|
||||
put_raw(KeyPath, Config) ->
|
||||
put_raw(KeyPath0, Config) ->
|
||||
KeyPath = [bin(K) || K <- KeyPath0],
|
||||
Putter = fun(Path, Map, Value) ->
|
||||
emqx_utils_maps:deep_force_put(Path, Map, Value)
|
||||
end,
|
||||
|
|
|
@ -297,6 +297,7 @@ t_update_config({init, Config}) ->
|
|||
];
|
||||
t_update_config(Config) when is_list(Config) ->
|
||||
emqx_config_handler:add_handler([?CONF_ROOT], emqx_authentication),
|
||||
ok = emqx_config_handler:add_handler([listeners, '?', '?', ?CONF_ROOT], emqx_authentication),
|
||||
ok = register_provider(?config("auth1"), ?MODULE),
|
||||
ok = register_provider(?config("auth2"), ?MODULE),
|
||||
Global = ?config(global),
|
||||
|
|
|
@ -279,7 +279,7 @@ does_module_exist(Mod) ->
|
|||
|
||||
clear_listeners() ->
|
||||
emqx_config:put([listeners], #{}),
|
||||
emqx_config:put_raw([listeners], #{}),
|
||||
emqx_config:put_raw([<<"listeners">>], #{}),
|
||||
ok.
|
||||
|
||||
assert_http_get(URL) ->
|
||||
|
|
Loading…
Reference in New Issue