Skip to content

Commit

Permalink
Fix the flapping bug
Browse files Browse the repository at this point in the history
Prior to this change, the banned until value will not be set
correctly because of wrong spell of config entry name .

This change fix this bug
  • Loading branch information
gilbertwong96 committed Jun 15, 2019
1 parent 3f1b788 commit 8fa24f0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions rebar.config
Expand Up @@ -2,10 +2,10 @@
[ {jsx, "2.9.0"} % hex
, {cowboy, "2.6.1"} % hex
, {gproc, "0.8.0"} % hex
, {ekka, "0.5.6"} % hex
, {replayq, "0.1.1"} %hex
, {esockd, "5.5.0"} %hex
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.3.1"}}}
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "v0.5.5"}}}
, {replayq, {git, "https://github.com/emqx/replayq", {tag, "v0.1.1"}}}
, {esockd, "5.5.0"}
, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.0.0"}}}
]}.

Expand Down
3 changes: 1 addition & 2 deletions src/emqx_cm_sup.erl
Expand Up @@ -30,9 +30,8 @@ init([]) ->
shutdown => 1000,
type => worker,
modules => [emqx_banned]},
FlappingOption = emqx_config:get_env(flapping_clean_interval, 3600000),
Flapping = #{id => flapping,
start => {emqx_flapping, start_link, [FlappingOption]},
start => {emqx_flapping, start_link, []},
restart => permanent,
shutdown => 1000,
type => worker,
Expand Down
13 changes: 8 additions & 5 deletions src/emqx_flapping.erl
Expand Up @@ -19,7 +19,7 @@

-behaviour(gen_statem).

-export([start_link/1]).
-export([start_link/0]).

%% This module is used to garbage clean the flapping records

Expand All @@ -33,6 +33,8 @@

-define(FLAPPING_TAB, ?MODULE).

-define(default_flapping_clean_interval, 3600000).

-export([check/3]).

-record(flapping,
Expand Down Expand Up @@ -96,11 +98,12 @@ check_flapping(Action, CheckCount, _Threshold = {TimesThreshold, TimeInterval},
%%--------------------------------------------------------------------
%% gen_statem callbacks
%%--------------------------------------------------------------------
-spec(start_link(TimerInterval :: [integer()]) -> startlink_ret()).
start_link(TimerInterval) ->
gen_statem:start_link({local, ?MODULE}, ?MODULE, [TimerInterval], []).
-spec(start_link() -> startlink_ret()).
start_link() ->
gen_statem:start_link({local, ?MODULE}, ?MODULE, [], []).

init([TimerInterval]) ->
init([]) ->
TimerInterval = emqx_config:get_env(flapping_clean_interval, ?default_flapping_clean_interval),
TabOpts = [ public
, set
, {keypos, 2}
Expand Down
2 changes: 1 addition & 1 deletion src/emqx_protocol.erl
Expand Up @@ -961,7 +961,7 @@ do_flapping_detect(Action, #pstate{zone = Zone,
Threshold = emqx_zone:get_env(Zone, flapping_threshold, {10, 60}),
case emqx_flapping:check(Action, ClientId, Threshold) of
flapping ->
BanExpiryInterval = emqx_zone:get_env(Zone, flapping_ban_expiry_interval, 3600000),
BanExpiryInterval = emqx_zone:get_env(Zone, flapping_banned_expiry_interval, 3600000),
Until = erlang:system_time(second) + BanExpiryInterval,
emqx_banned:add(#banned{who = {client_id, ClientId},
reason = <<"flapping">>,
Expand Down

0 comments on commit 8fa24f0

Please sign in to comment.