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

This commit is contained in:
Andrew Mayorov 2024-06-03 14:45:39 +02:00 committed by Serge Tupchii
parent e0604e3af6
commit ede35df24a
1 changed files with 8 additions and 1 deletions

View File

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