From c216dfd96b7378a1609b3d9eff305110cf9292c9 Mon Sep 17 00:00:00 2001 From: Thales Macedo Garitezi Date: Fri, 30 Jun 2023 15:40:40 -0300 Subject: [PATCH] fix(mysql_bridge): make nxdomain a 400 API error Fixes https://emqx.atlassian.net/browse/EMQX-10460 --- apps/emqx_bridge/src/emqx_bridge_api.erl | 10 +++++++--- apps/emqx_mysql/rebar.config | 2 +- changes/ee/fix-11175.en.md | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changes/ee/fix-11175.en.md diff --git a/apps/emqx_bridge/src/emqx_bridge_api.erl b/apps/emqx_bridge/src/emqx_bridge_api.erl index 7a03b24ca..57933029d 100644 --- a/apps/emqx_bridge/src/emqx_bridge_api.erl +++ b/apps/emqx_bridge/src/emqx_bridge_api.erl @@ -985,9 +985,13 @@ call_operation(NodeOrAll, OperFunc, Args = [_Nodes, BridgeType, BridgeName]) -> {error, timeout} -> ?SERVICE_UNAVAILABLE(<<"Request timeout">>); {error, {start_pool_failed, Name, Reason}} -> - ?SERVICE_UNAVAILABLE( - bin(io_lib:format("Failed to start ~p pool for reason ~p", [Name, Reason])) - ); + Msg = bin(io_lib:format("Failed to start ~p pool for reason ~p", [Name, Reason])), + case Reason of + nxdomain -> + ?BAD_REQUEST(Msg); + _ -> + ?SERVICE_UNAVAILABLE(Msg) + end; {error, not_found} -> BridgeId = emqx_bridge_resource:bridge_id(BridgeType, BridgeName), ?SLOG(warning, #{ diff --git a/apps/emqx_mysql/rebar.config b/apps/emqx_mysql/rebar.config index 58b6665ad..668e437f3 100644 --- a/apps/emqx_mysql/rebar.config +++ b/apps/emqx_mysql/rebar.config @@ -3,7 +3,7 @@ {erl_opts, [debug_info]}. {deps, [ %% NOTE: mind ecpool version when updating eredis_cluster version - {mysql, {git, "https://github.com/emqx/mysql-otp", {tag, "1.7.2"}}}, + {mysql, {git, "https://github.com/emqx/mysql-otp", {tag, "1.7.3"}}}, {emqx_connector, {path, "../../apps/emqx_connector"}}, {emqx_resource, {path, "../../apps/emqx_resource"}} ]}. diff --git a/changes/ee/fix-11175.en.md b/changes/ee/fix-11175.en.md new file mode 100644 index 000000000..24a9def70 --- /dev/null +++ b/changes/ee/fix-11175.en.md @@ -0,0 +1 @@ +Now when using a nonexistent hostname for connecting to MySQL will result in a 400 error rather than 503 in the HTTP API.