From 8521d8dac59cb47b1c641130e7fc4ef26dfd6631 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 8 Sep 2022 16:13:05 +0800 Subject: [PATCH 1/3] fix(time): replace os:system_time with erlang:system_time Avoid the problem of inaccurate timers caused by mixing erlang:system_time/0-1 and os:system_time/0-1 --- apps/emqx_authn/src/simple_authn/emqx_authn_jwt.erl | 2 +- apps/emqx_modules/src/emqx_delayed.erl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/emqx_authn/src/simple_authn/emqx_authn_jwt.erl b/apps/emqx_authn/src/simple_authn/emqx_authn_jwt.erl index d41a7fc69..0509cfd62 100644 --- a/apps/emqx_authn/src/simple_authn/emqx_authn_jwt.erl +++ b/apps/emqx_authn/src/simple_authn/emqx_authn_jwt.erl @@ -399,7 +399,7 @@ do_verify(JWT, [JWK | More], VerifyClaims) -> end. verify_claims(Claims, VerifyClaims0) -> - Now = os:system_time(seconds), + Now = erlang:system_time(seconds), VerifyClaims = [ {<<"exp">>, fun(ExpireTime) -> diff --git a/apps/emqx_modules/src/emqx_delayed.erl b/apps/emqx_modules/src/emqx_delayed.erl index 99bd62022..ac7f75158 100644 --- a/apps/emqx_modules/src/emqx_delayed.erl +++ b/apps/emqx_modules/src/emqx_delayed.erl @@ -296,7 +296,7 @@ handle_cast(Msg, State) -> %% Do Publish... handle_info({timeout, TRef, do_publish}, State = #{publish_timer := TRef}) -> - DeletedKeys = do_publish(mnesia:dirty_first(?TAB), os:system_time(seconds)), + DeletedKeys = do_publish(mnesia:dirty_first(?TAB), erlang:system_time(seconds)), lists:foreach(fun(Key) -> mria:dirty_delete(?TAB, Key) end, DeletedKeys), {noreply, ensure_publish_timer(State#{publish_timer := undefined, publish_at := 0})}; handle_info(stats, State = #{stats_fun := StatsFun}) -> @@ -347,12 +347,12 @@ ensure_publish_timer(State) -> ensure_publish_timer('$end_of_table', State) -> State#{publish_timer := undefined, publish_at := 0}; ensure_publish_timer({Ts, _Id}, State = #{publish_timer := undefined}) -> - ensure_publish_timer(Ts, os:system_time(seconds), State); + ensure_publish_timer(Ts, erlang:system_time(seconds), State); ensure_publish_timer({Ts, _Id}, State = #{publish_timer := TRef, publish_at := PubAt}) when Ts < PubAt -> ok = emqx_misc:cancel_timer(TRef), - ensure_publish_timer(Ts, os:system_time(seconds), State); + ensure_publish_timer(Ts, erlang:system_time(seconds), State); ensure_publish_timer(_Key, State) -> State. From 641763d4d7b35f4d27e134c73d9df9043c497e26 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 8 Sep 2022 16:14:42 +0800 Subject: [PATCH 2/3] chore: update app.src --- apps/emqx_modules/src/emqx_modules.app.src | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/emqx_modules/src/emqx_modules.app.src b/apps/emqx_modules/src/emqx_modules.app.src index 30c9ec3e9..2fa38dae3 100644 --- a/apps/emqx_modules/src/emqx_modules.app.src +++ b/apps/emqx_modules/src/emqx_modules.app.src @@ -1,7 +1,7 @@ %% -*- mode: erlang -*- {application, emqx_modules, [ {description, "EMQX Modules"}, - {vsn, "5.0.3"}, + {vsn, "5.0.4"}, {modules, []}, {applications, [kernel, stdlib, emqx]}, {mod, {emqx_modules_app, []}}, From de8bf0909c6557ae6bb4fe4e4f8878840490c282 Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 8 Sep 2022 16:16:07 +0800 Subject: [PATCH 3/3] chore: update changes --- CHANGES-5.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES-5.0.md b/CHANGES-5.0.md index c5d47e3df..d636cd44b 100644 --- a/CHANGES-5.0.md +++ b/CHANGES-5.0.md @@ -8,6 +8,7 @@ * Speed up dispatching of shared subscription messages in a cluster [#8893](https://github.com/emqx/emqx/pull/8893) * Fix the extra / prefix when CoAP gateway parsing client topics. [#8658](https://github.com/emqx/emqx/pull/8658) * Speed up updating the configuration, When some nodes in the cluster are down. [#8857](https://github.com/emqx/emqx/pull/8857) +* Fix delayed publish inaccurate caused by os time change. [#8926](https://github.com/emqx/emqx/pull/8926) ## Enhancements