From 3bc6e546e0f716209f637df9754a2c05faa4febd Mon Sep 17 00:00:00 2001 From: zhongwencool Date: Thu, 25 Jan 2024 12:20:30 +0800 Subject: [PATCH] fix: reboot emqx_dashboard after emqx_licencse --- apps/emqx_machine/src/emqx_machine_boot.erl | 20 +++++++-- apps/emqx_machine/test/emqx_machine_SUITE.erl | 42 ++++++++++++------- changes/ee/fix-12390.en.md | 1 + 3 files changed, 45 insertions(+), 18 deletions(-) create mode 100644 changes/ee/fix-12390.en.md diff --git a/apps/emqx_machine/src/emqx_machine_boot.erl b/apps/emqx_machine/src/emqx_machine_boot.erl index 08cf8c448..fb2c94758 100644 --- a/apps/emqx_machine/src/emqx_machine_boot.erl +++ b/apps/emqx_machine/src/emqx_machine_boot.erl @@ -166,8 +166,9 @@ is_app(Name) -> sorted_reboot_apps() -> RebootApps = reboot_apps(), Apps0 = [{App, app_deps(App, RebootApps)} || App <- RebootApps], - Apps = inject_bridge_deps(Apps0), - sorted_reboot_apps(Apps). + Apps1 = inject_bridge_deps(Apps0), + Apps2 = inject_dashboard_deps(Apps1), + sorted_reboot_apps(Apps2). app_deps(App, RebootApps) -> case application:get_key(App, applications) of @@ -193,6 +194,18 @@ inject_bridge_deps(RebootAppDeps) -> end, RebootAppDeps ). +inject_dashboard_deps(Reboots) -> + Apps = [emqx_license], + Deps = lists:filter(fun(App) -> lists:keymember(App, 1, Reboots) end, Apps), + lists:map( + fun + ({emqx_dashboard, Deps0}) when is_list(Deps0) -> + {emqx_dashboard, Deps0 ++ Deps}; + (App) -> + App + end, + Reboots + ). sorted_reboot_apps(Apps) -> G = digraph:new(), @@ -201,7 +214,8 @@ sorted_reboot_apps(Apps) -> case digraph_utils:topsort(G) of Sorted when is_list(Sorted) -> %% ensure emqx_conf boot up first - [emqx_conf | Sorted ++ (NoDepApps -- Sorted)]; + AllApps = Sorted ++ (NoDepApps -- Sorted), + [emqx_conf | lists:delete(emqx_conf, AllApps)]; false -> Loops = find_loops(G), error({circular_application_dependency, Loops}) diff --git a/apps/emqx_machine/test/emqx_machine_SUITE.erl b/apps/emqx_machine/test/emqx_machine_SUITE.erl index 7b64df05c..1a0818c86 100644 --- a/apps/emqx_machine/test/emqx_machine_SUITE.erl +++ b/apps/emqx_machine/test/emqx_machine_SUITE.erl @@ -24,25 +24,27 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("snabbkaffe/include/snabbkaffe.hrl"). +-define(APPS, [ + emqx_prometheus, + emqx_modules, + emqx_dashboard, + emqx_gateway, + emqx_resource, + emqx_rule_engine, + emqx_bridge, + emqx_management, + emqx_retainer, + emqx_exhook, + emqx_auth, + emqx_plugin, + emqx_opentelemetry +]). + all() -> emqx_common_test_helpers:all(?MODULE). init_per_suite(Config) -> emqx_common_test_helpers:start_apps([emqx_conf, emqx_opentelemetry]), - application:set_env(emqx_machine, applications, [ - emqx_prometheus, - emqx_modules, - emqx_dashboard, - emqx_gateway, - emqx_resource, - emqx_rule_engine, - emqx_bridge, - emqx_management, - emqx_retainer, - emqx_exhook, - emqx_auth, - emqx_plugin, - emqx_opentelemetry - ]), + application:load(emqx_dashboard), Config. end_per_suite(_Config) -> @@ -60,7 +62,11 @@ init_per_testcase(t_open_ports_check = TestCase, Config) -> ], Nodes = emqx_cth_cluster:start(Cluster, #{work_dir => emqx_cth_suite:work_dir(TestCase, Config)}), [{nodes, Nodes} | Config]; +init_per_testcase(t_sorted_reboot_apps, Config) -> + application:set_env(emqx_machine, applications, ?APPS ++ [emqx_license]), + Config; init_per_testcase(_TestCase, Config) -> + application:set_env(emqx_machine, applications, ?APPS), Config. end_per_testcase(t_custom_shard_transports, Config) -> @@ -88,6 +94,12 @@ t_shutdown_reboot(_Config) -> ok = emqx_machine_boot:stop_apps(), false = emqx:is_running(node()). +t_sorted_reboot_apps(_Config) -> + Apps = emqx_machine_boot:sorted_reboot_apps(), + SortApps = [App || App <- Apps, (App =:= emqx_dashboard orelse App =:= emqx_license)], + %% make sure emqx_license start early than emqx_dashboard + ?assertEqual([emqx_license, emqx_dashboard], SortApps). + t_custom_shard_transports(_Config) -> %% used to ensure the atom exists Shard = test_shard, diff --git a/changes/ee/fix-12390.en.md b/changes/ee/fix-12390.en.md new file mode 100644 index 000000000..f5d30a3f7 --- /dev/null +++ b/changes/ee/fix-12390.en.md @@ -0,0 +1 @@ +Fixed /license API request maybe crash during cluster join processes.