瀏覽代碼

Merge pull request #12041 from thalesmg/ds-estimate-last-alive-m-20231128

fix(ds_session): take conservative estimate of `last_alive_at` when bumping
Thales Macedo Garitezi 2 年之前
父節點
當前提交
fdafe2493e
共有 1 個文件被更改,包括 7 次插入2 次删除
  1. 7 2
      apps/emqx/src/emqx_persistent_session_ds.erl

+ 7 - 2
apps/emqx/src/emqx_persistent_session_ds.erl

@@ -426,8 +426,13 @@ handle_timeout(_ClientInfo, get_streams, Session) ->
     ensure_timer(get_streams),
     ensure_timer(get_streams),
     {ok, [], Session};
     {ok, [], Session};
 handle_timeout(_ClientInfo, bump_last_alive_at, Session0) ->
 handle_timeout(_ClientInfo, bump_last_alive_at, Session0) ->
-    NowMS = now_ms(),
-    Session = session_set_last_alive_at_trans(Session0, NowMS),
+    %% Note: we take a pessimistic approach here and assume that the client will be alive
+    %% until the next bump timeout.  With this, we avoid garbage collecting this session
+    %% too early in case the session/connection/node crashes earlier without having time
+    %% to commit the time.
+    BumpInterval = emqx_config:get([session_persistence, last_alive_update_interval]),
+    EstimatedLastAliveAt = now_ms() + BumpInterval,
+    Session = session_set_last_alive_at_trans(Session0, EstimatedLastAliveAt),
     ensure_timer(bump_last_alive_at),
     ensure_timer(bump_last_alive_at),
     {ok, [], Session}.
     {ok, [], Session}.