From 44d3eff094ac123fb9420707abfae07b827d0dc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=A5=87=E6=80=AA?= Date: Tue, 19 Feb 2019 14:00:34 +0800 Subject: [PATCH] Auto-pull-request-by-2019-02-19 (#2232) * Update Copyright to 2019 (#2191) * Disable bridges by default (#2189) * Fix warning logger args emqx#2195 * Ambiguity elimination (#2217) * Fix emqx_ws_connection: prevent crashes on pong (#2210) * Issue#2184 (#2194) * Delete dep-vsn-check * Format app.src --- Makefile | 23 ------------- etc/emqx.conf | 58 ++++++++++++++++----------------- include/logger.hrl | 2 +- priv/emqx.schema | 14 ++++---- rebar.config.script | 1 - src/emqx.app.src | 3 +- src/emqx_ws_connection.erl | 10 +++++- test/emqx_ct_broker_helpers.erl | 28 ++++++++++++++++ 8 files changed, 76 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index 16c9795b1..0d9bfb7c4 100644 --- a/Makefile +++ b/Makefile @@ -113,26 +113,3 @@ rebar-clean: distclean:: @rm -rf _build cover deps logs log data @rm -f rebar.lock compile_commands.json cuttlefish - -## Below are for version consistency check during erlang.mk and rebar3 dual mode support -none= -space = $(none) $(none) -comma = , -quote = \" -curly_l = "{" -curly_r = "}" -dep-versions = [$(foreach dep,$(DEPS) $(BUILD_DEPS),$(curly_l)$(dep),$(quote)$(word $(words $(dep_$(dep))),$(dep_$(dep)))$(quote)$(curly_r)$(comma))[]] - -.PHONY: dep-vsn-check -dep-vsn-check: - $(verbose) erl -noshell -eval \ - "MkVsns = lists:sort(lists:flatten($(dep-versions))), \ - {ok, Conf} = file:consult('rebar.config'), \ - {_, Deps1} = lists:keyfind(deps, 1, Conf), \ - {_, Deps2} = lists:keyfind(github_emqx_deps, 1, Conf), \ - F = fun({N, V}) when is_list(V) -> {N, V}; ({N, {git, _, {branch, V}}}) -> {N, V} end, \ - RebarVsns = lists:sort(lists:map(F, Deps1 ++ Deps2)), \ - case {RebarVsns -- MkVsns, MkVsns -- RebarVsns} of \ - {[], []} -> halt(0); \ - {Rebar, Mk} -> erlang:error({deps_version_discrepancy, [{rebar, Rebar}, {mk, Mk}]}) \ - end." diff --git a/etc/emqx.conf b/etc/emqx.conf index fc37427e6..d762aef7e 100644 --- a/etc/emqx.conf +++ b/etc/emqx.conf @@ -286,32 +286,32 @@ rpc.tcp_client_port = 5369 ## RCP Client connect timeout. ## ## Value: Seconds -rpc.connect_timeout = 5000 +rpc.connect_timeout = 5s ## TCP send timeout of RPC client and server. ## ## Value: Seconds -rpc.send_timeout = 5000 +rpc.send_timeout = 5s ## Authentication timeout ## ## Value: Seconds -rpc.authentication_timeout = 5000 +rpc.authentication_timeout = 5s ## Default receive timeout for call() functions ## ## Value: Seconds -rpc.call_receive_timeout = 15000 +rpc.call_receive_timeout = 15s ## Socket idle keepalive. ## ## Value: Seconds -rpc.socket_keepalive_idle = 900 +rpc.socket_keepalive_idle = 900s ## TCP Keepalive probes interval. ## -## Value: Integer -rpc.socket_keepalive_interval = 75 +## Value: Seconds +rpc.socket_keepalive_interval = 75s ## Probes lost to close the connection ## @@ -947,7 +947,7 @@ listener.tcp.internal.send_timeout = 5s ## See: listener.tcp.$name.send_timeout_close ## ## Value: on | off -listener.tcp.external.send_timeout_close = on +listener.tcp.internal.send_timeout_close = on ## The TCP receive buffer(os kernel) for internal MQTT connections. ## @@ -1596,29 +1596,29 @@ listener.wss.external.ciphers = ECDHE-ECDSA-AES256-GCM-SHA384,ECDHE-RSA-AES256-G ## Value: enum ## manual ## auto -bridge.aws.start_type = manual +## bridge.aws.start_type = manual ## Bridge reconnect time. ## ## Value: Duration ## Default: 30 seconds -bridge.aws.reconnect_interval = 30s +## bridge.aws.reconnect_interval = 30s ## Retry interval for bridge QoS1 message delivering. ## ## Value: Duration -bridge.aws.retry_interval = 20s +## bridge.aws.retry_interval = 20s ## Inflight size. ## ## Value: Integer -bridge.aws.max_inflight = 32 +## bridge.aws.max_inflight = 32 ## Bridge address: node name for local bridge, host:port for remote. ## ## Value: String ## Example: emqx@127.0.0.1, 127.0.0.1:1883 -bridge.aws.address = 127.0.0.1:1883 +## bridge.aws.address = 127.0.0.1:1883 ## Protocol version of the bridge. ## @@ -1626,12 +1626,12 @@ bridge.aws.address = 127.0.0.1:1883 ## - mqttv5 ## - mqttv4 ## - mqttv3 -bridge.aws.proto_ver = mqttv4 +## bridge.aws.proto_ver = mqttv4 ## The ClientId of a remote bridge. ## ## Value: String -bridge.aws.client_id = bridge_aws +## bridge.aws.client_id = bridge_aws ## The Clean start flag of a remote bridge. ## @@ -1645,62 +1645,62 @@ bridge.aws.client_id = bridge_aws ## The username for a remote bridge. ## ## Value: String -bridge.aws.username = user +## bridge.aws.username = user ## The password for a remote bridge. ## ## Value: String -bridge.aws.password = passwd +## bridge.aws.password = passwd ## Mountpoint of the bridge. ## ## Value: String -bridge.aws.mountpoint = bridge/aws/${node}/ +## bridge.aws.mountpoint = bridge/aws/${node}/ ## Ping interval of a down bridge. ## ## Value: Duration ## Default: 10 seconds -bridge.aws.keepalive = 60s +## bridge.aws.keepalive = 60s ## Forward message topics ## ## Value: String ## Example: topic1/#,topic2/# -bridge.aws.forwards = topic1/#,topic2/# +## bridge.aws.forwards = topic1/#,topic2/# ## Subscriptions of the bridge topic. ## ## Value: String -bridge.aws.subscription.1.topic = cmd/topic1 +## bridge.aws.subscription.1.topic = cmd/topic1 ## Subscriptions of the bridge qos. ## ## Value: Number -bridge.aws.subscription.1.qos = 1 +## bridge.aws.subscription.1.qos = 1 ## Subscriptions of the bridge topic. ## ## Value: String -bridge.aws.subscription.2.topic = cmd/topic2 +## bridge.aws.subscription.2.topic = cmd/topic2 ## Subscriptions of the bridge qos. ## ## Value: Number -bridge.aws.subscription.2.qos = 1 +## bridge.aws.subscription.2.qos = 1 ## If enabled, queue would be written into disk more quickly. ## However, If disabled, some message would be dropped in ## the situation emqx crashed. ## ## Value: on | off -bridge.aws.queue.mem_cache = on +## bridge.aws.queue.mem_cache = on ## Batch size for buffer queue stored ## ## Value: Integer ## default: 1000 -bridge.aws.queue.batch_size = 1000 +## bridge.aws.queue.batch_size = 1000 ## Base directory for replayq to store messages on disk ## If this config entry is missing or set to undefined, @@ -1709,18 +1709,18 @@ bridge.aws.queue.batch_size = 1000 ## this config entry would have no effect on mqueue ## ## Value: String -bridge.aws.queue.replayq_dir = {{ platform_data_dir }}/emqx_aws_bridge/ +## bridge.aws.queue.replayq_dir = {{ platform_data_dir }}/emqx_aws_bridge/ ## Replayq segment size ## ## Value: Bytesize -bridge.aws.queue.replayq_seg_bytes = 10MB +## bridge.aws.queue.replayq_seg_bytes = 10MB ## Bribge to remote server via SSL. ## ## Value: on | off -bridge.aws.ssl = off +## bridge.aws.ssl = off ## PEM-encoded CA certificates of the bridge. ## diff --git a/include/logger.hrl b/include/logger.hrl index f828a1fb3..a2ee404d9 100644 --- a/include/logger.hrl +++ b/include/logger.hrl @@ -24,7 +24,7 @@ -define(NOTICE(Format, Args), ?LOG(notice, Format, Args)). -define(WARN(Format), ?LOG(warning, Format, [])). --define(WARN(Format, Args), ?LOG(warning, Format, [])). +-define(WARN(Format, Args), ?LOG(warning, Format, Args)). -define(ERROR(Format), ?LOG(error, Format, [])). -define(ERROR(Format, Args), ?LOG(error, Format, Args)). diff --git a/priv/emqx.schema b/priv/emqx.schema index 1f8e4fa6b..2136bacad 100644 --- a/priv/emqx.schema +++ b/priv/emqx.schema @@ -324,38 +324,38 @@ end}. %% Client connect timeout {mapping, "rpc.connect_timeout", "gen_rpc.connect_timeout", [ - {default, 5000}, - {datatype, integer} + {default, "5s"}, + {datatype, {duration, ms}} ]}. %% Client and Server send timeout {mapping, "rpc.send_timeout", "gen_rpc.send_timeout", [ {default, 5000}, - {datatype, integer} + {datatype, {duration, ms}} ]}. %% Authentication timeout {mapping, "rpc.authentication_timeout", "gen_rpc.authentication_timeout", [ {default, 5000}, - {datatype, integer} + {datatype, {duration, ms}} ]}. %% Default receive timeout for call() functions {mapping, "rpc.call_receive_timeout", "gen_rpc.call_receive_timeout", [ {default, 15000}, - {datatype, integer} + {datatype, {duration, ms}} ]}. %% Socket keepalive configuration {mapping, "rpc.socket_keepalive_idle", "gen_rpc.socket_keepalive_idle", [ {default, 7200}, - {datatype, integer} + {datatype, {duration, s}} ]}. %% Seconds between probes {mapping, "rpc.socket_keepalive_interval", "gen_rpc.socket_keepalive_interval", [ {default, 75}, - {datatype, integer} + {datatype, {duration, s}} ]}. %% Probes lost to close the connection diff --git a/rebar.config.script b/rebar.config.script index aed271af8..2c04540dc 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -1,4 +1,3 @@ - CONFIG0 = case os:getenv("REBAR_GIT_CLONE_OPTIONS") of "--depth 1" -> CONFIG; diff --git a/src/emqx.app.src b/src/emqx.app.src index d4613a5af..f9c174ae3 100644 --- a/src/emqx.app.src +++ b/src/emqx.app.src @@ -3,7 +3,8 @@ {vsn,"git"}, {modules,[]}, {registered,[emqx_sup]}, - {applications,[kernel,stdlib,jsx,gproc,gen_rpc,esockd,cowboy,replayq]}, + {applications,[kernel,stdlib,jsx,gproc,gen_rpc,esockd,cowboy, + replayq]}, {env,[]}, {mod,{emqx_app,[]}}, {maintainers,["Feng Lee "]}, diff --git a/src/emqx_ws_connection.erl b/src/emqx_ws_connection.erl index 426677ff5..fec52995f 100644 --- a/src/emqx_ws_connection.erl +++ b/src/emqx_ws_connection.erl @@ -189,7 +189,15 @@ websocket_handle({binary, Data}, State = #state{parser_state = ParserState, _:Error -> ?LOG(error, "Frame error:~p~nFrame data: ~p", [Error, Data]), shutdown(parse_error, State) - end. + end; +%% Pings should be replied with pongs, cowboy does it automatically +%% Pongs can be safely ignored. Clause here simply prevents crash. +websocket_handle(Frame, State) + when Frame =:= ping; Frame =:= pong -> + {ok, ensure_stats_timer(State)}; +websocket_handle({FrameType, _}, State) + when FrameType =:= ping; FrameType =:= pong -> + {ok, ensure_stats_timer(State)}. websocket_info({call, From, info}, State) -> gen_server:reply(From, info(State)), diff --git a/test/emqx_ct_broker_helpers.erl b/test/emqx_ct_broker_helpers.erl index 7ea2daaeb..1ab79e8a9 100644 --- a/test/emqx_ct_broker_helpers.erl +++ b/test/emqx_ct_broker_helpers.erl @@ -56,6 +56,7 @@ run_setup_steps() -> NewConfig = generate_config(), lists:foreach(fun set_app_env/1, NewConfig), + set_bridge_env(), application:ensure_all_started(?APP). run_teardown_steps() -> @@ -88,6 +89,10 @@ set_app_env({App, Lists}) -> application:set_env(App, Par, Var) end, Lists). +set_bridge_env() -> + BridgeEnvs = bridge_conf(), + application:set_env(?APP, bridges, BridgeEnvs). + change_opts(SslType) -> {ok, Listeners} = application:get_env(?APP, listeners), NewListeners = @@ -149,3 +154,26 @@ flush(Msgs) -> after 0 -> lists:reverse(Msgs) end. + +bridge_conf() -> + [{aws, + [{username,"user"}, + {address,"127.0.0.1:1883"}, + {clean_start,true}, + {client_id,"bridge_aws"}, + {forwards,["topic1/#","topic2/#"]}, + {keepalive,60000}, + {max_inflight,32}, + {mountpoint,"bridge/aws/${node}/"}, + {password,"passwd"}, + {proto_ver,mqttv4}, + {queue, + #{batch_size => 1000,mem_cache => true, + replayq_dir => "data/emqx_aws_bridge/", + replayq_seg_bytes => 10485760}}, + {reconnect_interval,30000}, + {retry_interval,20000}, + {ssl,false}, + {ssl_opts,[{versions,[tlsv1,'tlsv1.1','tlsv1.2']}]}, + {start_type,manual}, + {subscriptions,[{"cmd/topic1",1},{"cmd/topic2",1}]}]}]. \ No newline at end of file