fix heartbeat

This commit is contained in:
anlicheng 2026-05-09 17:19:42 +08:00
parent 7fd82ac61d
commit 7f3775b697

View File

@ -311,13 +311,17 @@ handle_event(cast, heartbeat, _, State = #state{uuid = UUID, heartbeat_counter =
maybe_mark_host_online(UUID),
{keep_state, State#state{heartbeat_counter = HeartbeatCounter + 1}};
%% 线,
handle_event(info, {timeout, _, heartbeat_ticker}, _, State = #state{uuid = UUID, heartbeat_counter = 0, channel_pid = ChannelPid}) ->
%% UDP SSL channel host 线
handle_event(info, {timeout, _, heartbeat_ticker}, _, State = #state{uuid = UUID, heartbeat_counter = 0, channel_pid = ChannelPid}) when is_pid(ChannelPid) ->
logger:warning("[iot_host] uuid: ~p, udp heartbeat lost but ssl channel is alive: ~p", [UUID, ChannelPid]),
maybe_mark_host_online(UUID),
erlang:start_timer(?HEARTBEAT_INTERVAL, self(), heartbeat_ticker),
{keep_state, State#state{heartbeat_counter = 0}};
%% UDP SSL channel线,
handle_event(info, {timeout, _, heartbeat_ticker}, _, State = #state{uuid = UUID, heartbeat_counter = 0}) ->
logger:warning("[iot_host] uuid: ~p, heartbeat lost, devices will unknown", [UUID]),
maybe_mark_host_offline(UUID),
%% channel
is_pid(ChannelPid) andalso ssl_channel:stop(ChannelPid, closed),
erlang:start_timer(?HEARTBEAT_INTERVAL, self(), heartbeat_ticker),
{keep_state, State#state{channel_pid = undefined, has_session = false, heartbeat_counter = 0}};