Skip to content

Commit e014a02

Browse files
committed
fix(data_updater): ensure GenServer timeouts reset properly
There were cases where DataUpdater GenServer processes might not shut down automatically due to missing timeout parameters in several message handlers. This would have caused processes to remain alive indefinitely, consuming resources. The following handlers were missing timeout parameters: - handle_heartbeat: both success and failure cases - handle_internal: continue case and failure case - handle_control: success case Without proper timeout resets, the 3-hour deactivation interval never triggered, preventing automatic cleanup of disconnected device processes. Signed-off-by: Davide Briani <davide.briani@secomind.com>
1 parent 251dad2 commit e014a02

File tree

1 file changed

+9
-5
lines changed
  • apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/data_updater

1 file changed

+9
-5
lines changed

apps/astarte_data_updater_plant/lib/astarte_data_updater_plant/data_updater/server.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,28 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Server do
8181
# TODO remove this when all heartbeats will be moved to internal
8282
@impl GenServer
8383
def handle_cast({:handle_heartbeat, message_id, timestamp}, state) do
84+
timeout = Config.data_updater_deactivation_interval_ms!()
85+
8486
if MessageTracker.can_process_message(state.message_tracker, message_id) do
8587
new_state = Core.HeartbeatHandler.handle_heartbeat(state, message_id, timestamp)
86-
{:noreply, new_state}
88+
{:noreply, new_state, timeout}
8789
else
88-
{:noreply, state}
90+
{:noreply, state, timeout}
8991
end
9092
end
9193

9294
@impl GenServer
9395
def handle_cast({:handle_internal, payload, path, message_id, timestamp}, state) do
96+
timeout = Config.data_updater_deactivation_interval_ms!()
97+
9498
if MessageTracker.can_process_message(state.message_tracker, message_id) do
9599
case Impl.handle_internal(state, payload, path, message_id, timestamp) do
96-
{:continue, new_state} -> {:noreply, new_state}
100+
{:continue, new_state} -> {:noreply, new_state, timeout}
97101
# No more messages from this device, time out now in order to stop this process
98102
{:stop, new_state} -> {:noreply, new_state, 0}
99103
end
100104
else
101-
{:noreply, state}
105+
{:noreply, state, timeout}
102106
end
103107
end
104108

@@ -141,7 +145,7 @@ defmodule Astarte.DataUpdaterPlant.DataUpdater.Server do
141145

142146
if MessageTracker.can_process_message(state.message_tracker, message_id) do
143147
new_state = Impl.handle_control(state, payload, path, message_id, timestamp)
144-
{:noreply, new_state}
148+
{:noreply, new_state, timeout}
145149
else
146150
{:noreply, state, timeout}
147151
end

0 commit comments

Comments
 (0)