Просмотр исходного кода

fix(cluster-link): cancel heartbeats on client down

Andrew Mayorov 1 год назад
Родитель
Сommit
ede35df24a
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      apps/emqx_cluster_link/src/emqx_cluster_link_router_syncer.erl

+ 8 - 1
apps/emqx_cluster_link/src/emqx_cluster_link_router_syncer.erl

@@ -457,7 +457,8 @@ handle_client_down(Reason, St = #st{target = TargetCluster, actor = Actor}) ->
     %% TODO: syncer may be already down due to one_for_all strategy
     ok = close_syncer(TargetCluster, Actor),
     _ = maybe_alarm(Reason, St),
-    process_connect(St#st{client = undefined, error = Reason, status = connecting}).
+    NSt = cancel_heartbeat(St),
+    process_connect(NSt#st{client = undefined, error = Reason, status = connecting}).
 
 process_bootstrap(St = #st{bootstrapped = false}, _NeedBootstrap) ->
     run_bootstrap(St);
@@ -478,6 +479,12 @@ schedule_heartbeat(St = #st{heartbeat_timer = undefined}) ->
     TRef = erlang:start_timer(Timeout, self(), heartbeat),
     St#st{heartbeat_timer = TRef}.
 
+cancel_heartbeat(St = #st{heartbeat_timer = undefined}) ->
+    St;
+cancel_heartbeat(St = #st{heartbeat_timer = TRef}) ->
+    ok = emqx_utils:cancel_timer(TRef),
+    St#st{heartbeat_timer = undefined}.
+
 %% Bootstrapping.
 %% Responsible for transferring local routing table snapshot to the target
 %% cluster. Does so either during the initial startup or when MQTT connection