Prechádzať zdrojové kódy

Merge pull request #14313 from lafirest/fix/api_bootstrap

fix(api_keys): only load bootstrap file on `core` node
lafirest 1 rok pred
rodič
commit
099be5ef8f

+ 9 - 4
apps/emqx_management/src/emqx_mgmt_auth.erl

@@ -117,10 +117,15 @@ post_config_update([api_key], _Req, NewConf, _OldConf, _AppEnvs) ->
 
 -spec try_init_bootstrap_file() -> ok | {error, _}.
 try_init_bootstrap_file() ->
-    File = bootstrap_file(),
-    ?SLOG(debug, #{msg => "init_bootstrap_api_keys_from_file", file => File}),
-    _ = init_bootstrap_file(File),
-    ok.
+    case mria_rlog:role() of
+        core ->
+            File = bootstrap_file(),
+            ?SLOG(debug, #{msg => "init_bootstrap_api_keys_from_file", file => File}),
+            _ = init_bootstrap_file(File),
+            ok;
+        _ ->
+            ok
+    end.
 
 create(Name, Enable, ExpiredAt, Desc, Role) ->
     ApiKey = generate_unique_api_key(Name),

+ 1 - 0
changes/ce/fix-14313.en.md

@@ -0,0 +1 @@
+Load the bootstrap file for the REST API keys only in the `core` nodes to avoid potential risk of EMQX getting stuck.