diff --git a/apps/emqx_gateway/src/emqx_gateway_conf.erl b/apps/emqx_gateway/src/emqx_gateway_conf.erl index cd1f64871..d2f6921e3 100644 --- a/apps/emqx_gateway/src/emqx_gateway_conf.erl +++ b/apps/emqx_gateway/src/emqx_gateway_conf.erl @@ -275,7 +275,7 @@ ret_gw(GwName, {ok, #{raw_config := GwConf}}) -> end, maps:to_list(SubConf)), [NLConfs | Acc] end, [], maps:to_list(LsConf)), - {ok, maps:merge(GwConf1, #{<<"listeners">> => NLsConf})}; + {ok, maps:merge(GwConf1, #{<<"listeners">> => lists:append(NLsConf)})}; ret_gw(_GwName, Err) -> Err. ret_authn(GwName, {ok, #{raw_config := GwConf}}) -> diff --git a/apps/emqx_gateway/src/emqx_gateway_utils.erl b/apps/emqx_gateway/src/emqx_gateway_utils.erl index 95720ff13..cc771ed95 100644 --- a/apps/emqx_gateway/src/emqx_gateway_utils.erl +++ b/apps/emqx_gateway/src/emqx_gateway_utils.erl @@ -46,7 +46,6 @@ ]). -export([ stringfy/1 - , parse_address/1 ]). -export([ normalize_config/1 @@ -332,19 +331,6 @@ stringfy(T) when is_list(T); is_binary(T) -> stringfy(T) -> iolist_to_binary(io_lib:format("~0p", [T])). --spec parse_address(binary() | list()) -> {list(), integer()}. -parse_address(S) when is_binary(S); is_list(S) -> - S1 = case is_binary(S) of - true -> lists:reverse(binary_to_list(S)); - _ -> lists:reverse(S) - end, - case re:split(S1, ":", [{parts, 2}, {return, list}]) of - [Port0, Host0] -> - {lists:reverse(Host0), list_to_integer(lists:reverse(Port0))}; - _ -> - error(badarg) - end. - -spec normalize_config(emqx_config:config()) -> list({ Type :: udp | tcp | ssl | dtls , Name :: atom() diff --git a/apps/emqx_gateway/src/exproto/emqx_exproto_impl.erl b/apps/emqx_gateway/src/exproto/emqx_exproto_impl.erl index 48dca4324..75057534f 100644 --- a/apps/emqx_gateway/src/exproto/emqx_exproto_impl.erl +++ b/apps/emqx_gateway/src/exproto/emqx_exproto_impl.erl @@ -148,13 +148,16 @@ stop_grpc_server(GwName) -> start_grpc_client_channel(_GwName, undefined) -> undefined; start_grpc_client_channel(GwName, Options = #{address := Address}) -> - {Host, Port} = try emqx_gateway_utils:parse_address(Address) - catch error : badarg -> - throw({badconf, #{key => address, - value => Address, - reason => illegal_grpc_address - }}) - end, + #{host := Host, port := Port} = + case emqx_http_lib:uri_parse(Address) of + {ok, URIMap0} -> URIMap0; + {error, _Reason} -> + throw({badconf, #{key => address, + value => Address, + reason => illegal_grpc_address + }}) + + end, case maps:to_list(maps:get(ssl, Options, #{})) of [] -> SvrAddr = compose_http_uri(http, Host, Port), @@ -170,7 +173,7 @@ start_grpc_client_channel(GwName, Options = #{address := Address}) -> compose_http_uri(Scheme, Host, Port) -> lists:flatten( io_lib:format( - "~s://~s:~w", [Scheme, Host, Port])). + "~s://~s:~w", [Scheme, inet:ntoa(Host), Port])). stop_grpc_client_channel(GwName) -> _ = grpc_client_sup:stop_channel_pool(GwName), diff --git a/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_impl.erl b/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_impl.erl index 47ed722b1..f4d73879d 100644 --- a/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_impl.erl +++ b/apps/emqx_gateway/src/lwm2m/emqx_lwm2m_impl.erl @@ -92,7 +92,7 @@ on_gateway_update(Config, Gateway, GwState = #{ctx := Ctx}) -> on_gateway_unload(_Gateway = #{ name := GwName, config := Config - }, _GwState = #{registry := RegPid}) -> - exit(RegPid, kill), + }, _GwState = #{registry := _RegPid}) -> + _ = try emqx_lwm2m_xml_object_db:stop() catch _ : _ -> ok end, Listeners = emqx_gateway_utils:normalize_config(Config), emqx_gateway_utils:stop_listeners(GwName, Listeners). diff --git a/apps/emqx_gateway/test/emqx_exproto_SUITE.erl b/apps/emqx_gateway/test/emqx_exproto_SUITE.erl index 993ed4975..69e9afbaf 100644 --- a/apps/emqx_gateway/test/emqx_exproto_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_exproto_SUITE.erl @@ -69,7 +69,7 @@ set_special_cfg(emqx_gateway) -> emqx_config:put( [gateway, exproto], #{server => #{bind => 9100}, - handler => #{address => "127.0.0.1:9001"}, + handler => #{address => "http://127.0.0.1:9001"}, listeners => listener_confs(LisType) }); set_special_cfg(_App) -> diff --git a/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl index f91347a6e..9b303c100 100644 --- a/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl @@ -172,7 +172,7 @@ t_gateway_exproto(_) -> %% post GwConf = #{name => <<"exproto">>, server => #{bind => <<"9100">>}, - handler => #{address => <<"127.0.0.1:9001">>}, + handler => #{address => <<"http://127.0.0.1:9001">>}, listeners => [ #{name => <<"def">>, type => <<"tcp">>, bind => <<"7993">>} ]