fix(banned): ensure the default timeout of `banned` is large enough

This commit is contained in:
firest 2022-12-22 18:14:54 +08:00
parent 1e3b0c3777
commit af3f0c9bb0
4 changed files with 33 additions and 1 deletions

View File

@ -59,6 +59,10 @@
-define(BANNED_TAB, ?MODULE).
%% The default expiration time should be infinite
%% but for compatibility, a large number (1 years) is used here to represent the 'infinite'
-define(EXPIRATION_TIME, 31536000).
-ifdef(TEST).
-compile(export_all).
-compile(nowarn_export_all).
@ -126,7 +130,7 @@ parse(Params) ->
By = maps:get(<<"by">>, Params, <<"mgmt_api">>),
Reason = maps:get(<<"reason">>, Params, <<"">>),
At = maps:get(<<"at">>, Params, erlang:system_time(second)),
Until = maps:get(<<"until">>, Params, At + 5 * 60),
Until = maps:get(<<"until">>, Params, At + ?EXPIRATION_TIME),
case Until > erlang:system_time(second) of
true ->
#banned{

View File

@ -20,6 +20,8 @@
-include_lib("eunit/include/eunit.hrl").
-define(EXPIRATION_TIME, 31536000).
all() ->
emqx_common_test_helpers:all(?MODULE).
@ -82,6 +84,28 @@ t_create(_Config) ->
{ok, #{<<"data">> := List}} = list_banned(),
Bans = lists:sort(lists:map(fun(#{<<"who">> := W, <<"as">> := A}) -> {A, W} end, List)),
?assertEqual([{<<"clientid">>, ClientId}, {<<"peerhost">>, PeerHost}], Bans),
ClientId2 = <<"TestClient2"/utf8>>,
ClientIdBanned2 = #{
as => As,
who => ClientId2,
by => By,
reason => Reason,
at => At
},
{ok, ClientIdBannedRes2} = create_banned(ClientIdBanned2),
Until2 = emqx_banned:to_rfc3339(Now + ?EXPIRATION_TIME),
?assertEqual(
#{
<<"as">> => As,
<<"at">> => At,
<<"by">> => By,
<<"reason">> => Reason,
<<"until">> => Until2,
<<"who">> => ClientId2
},
ClientIdBannedRes2
),
ok.
t_create_failed(_Config) ->

View File

@ -16,6 +16,8 @@
- Added the option to customize the clientid prefix of egress MQTT bridges. [#9609](https://github.com/emqx/emqx/pull/9609)
- Ensure the default expiration time of `banned` is large enough [#9599](https://github.com/emqx/emqx/pull/9599/).
## Bug fixes
- Trigger `message.dropped` hook when QoS2 message is resend by client with a same packet id, or 'awaiting_rel' queue is full [#9487](https://github.com/emqx/emqx/pull/9487).

View File

@ -16,6 +16,8 @@
- 增加了自定义出口MQTT桥的clientid前缀的选项。[#9609](https://github.com/emqx/emqx/pull/9609)
- 确保黑名单的默认超期时间足够长 [#9599](https://github.com/emqx/emqx/pull/9599/)。
## 修复
- 当 QoS2 消息被重发(使用相同 Packet ID),或当 'awaiting_rel' 队列已满时,触发消息丢弃钩子(`message.dropped`)及计数器 [#9487](https://github.com/emqx/emqx/pull/9487)。