From 8d480a1dc9c2b7154ebde7db894c3b95845242de Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 21 Feb 2023 20:29:30 +0100 Subject: [PATCH 1/3] fix(bin/emqx): fail fast if cookie is obviously wrong --- bin/emqx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/emqx b/bin/emqx index 9211bd338..4fdf24186 100755 --- a/bin/emqx +++ b/bin/emqx @@ -545,6 +545,10 @@ else logerr "Make sure environment variable EMQX_NODE__NAME is set to indicate for which node this command is intended." exit 1 fi + else + if [ -n "${EMQX_NODE__NAME:-}" ]; then + die "Node $EMQX_NODE__NAME is not running?" + fi fi ## We have no choiece but to read the bootstrap config (with environment overrides available in the current shell) [ -f "$EMQX_ETC_DIR"/emqx.conf ] || die "emqx.conf is not found in $EMQX_ETC_DIR" 1 @@ -940,9 +944,11 @@ if [ -n "${EMQX_NODE_COOKIE:-}" ]; then unset EMQX_NODE_COOKIE fi COOKIE="${EMQX_NODE__COOKIE:-}" -if [ -z "$COOKIE" ]; then - COOKIE="$(get_boot_config 'node.cookie')" +COOKIE_IN_USE="$(get_boot_config 'node.cookie')" +if [ -n "$COOKIE_IN_USE" ] && [ -n "$COOKIE" ] && [ "$COOKIE" != "$COOKIE_IN_USE" ]; then + die "EMQX_NODE__COOKIE is different from the cookie used by $NAME" fi +[ -z "$COOKIE" ] && COOKIE="$COOKIE_IN_USE" [ -z "$COOKIE" ] && COOKIE="$EMQX_DEFAULT_ERLANG_COOKIE" maybe_warn_default_cookie() { From 6a1085a8420147ec2598f341b286e71193f95fd0 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Tue, 21 Feb 2023 20:35:33 +0100 Subject: [PATCH 2/3] chore: change 'emqx_ctl' usage to 'emqx ctl' --- apps/emqx_ctl/src/emqx_ctl.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/emqx_ctl/src/emqx_ctl.erl b/apps/emqx_ctl/src/emqx_ctl.erl index a9aad0259..864b53d2a 100644 --- a/apps/emqx_ctl/src/emqx_ctl.erl +++ b/apps/emqx_ctl/src/emqx_ctl.erl @@ -149,7 +149,7 @@ help() -> [] -> print("No commands available.~n"); Cmds -> - print("Usage: ~ts~n", [?MODULE]), + print("Usage: ~ts~n", ["emqx ctl"]), lists:foreach( fun({_, {Mod, Cmd}, _}) -> print("~110..-s~n", [""]), From a638cc1d74abec88cb2a13b76808db580bad11c6 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 22 Feb 2023 13:54:02 +0100 Subject: [PATCH 3/3] docs: add change logs --- bin/emqx | 2 +- changes/ce/fix-10015.en.md | 7 +++++++ changes/ce/fix-10015.zh.md | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changes/ce/fix-10015.en.md create mode 100644 changes/ce/fix-10015.zh.md diff --git a/bin/emqx b/bin/emqx index 4fdf24186..f0366c09d 100755 --- a/bin/emqx +++ b/bin/emqx @@ -550,7 +550,7 @@ else die "Node $EMQX_NODE__NAME is not running?" fi fi - ## We have no choiece but to read the bootstrap config (with environment overrides available in the current shell) + ## We have no choice but to read the bootstrap config (with environment overrides available in the current shell) [ -f "$EMQX_ETC_DIR"/emqx.conf ] || die "emqx.conf is not found in $EMQX_ETC_DIR" 1 maybe_use_portable_dynlibs EMQX_BOOT_CONFIGS="$(call_hocon -s "$SCHEMA_MOD" -c "$EMQX_ETC_DIR"/emqx.conf multi_get "${CONF_KEYS[@]}")" diff --git a/changes/ce/fix-10015.en.md b/changes/ce/fix-10015.en.md new file mode 100644 index 000000000..5727a52cd --- /dev/null +++ b/changes/ce/fix-10015.en.md @@ -0,0 +1,7 @@ +To prevent errors caused by an incorrect EMQX node cookie provided from an environment variable, +we have implemented a fail-fast mechanism. +Previously, when an incorrect cookie was provided, the command would still attempt to ping the node, +leading to the error message 'Node xxx not responding to pings'. +With the new implementation, if a mismatched cookie is detected, +a message will be logged to indicate that the cookie is incorrect, +and the command will terminate with an error code of 1 without trying to ping the node. diff --git a/changes/ce/fix-10015.zh.md b/changes/ce/fix-10015.zh.md new file mode 100644 index 000000000..0f58fa99c --- /dev/null +++ b/changes/ce/fix-10015.zh.md @@ -0,0 +1,4 @@ +在 cookie 给错时,快速失败。 +在此修复前,即使 cookie 配置错误,emqx 命令仍然会尝试去 ping EMQX 节点, +并得到一个 "Node xxx not responding to pings" 的错误。 +修复后,如果发现 cookie 不一致,立即打印不一致的错误信息并退出。