fix(data_builder): clear weather cache in after block

If build_packet_data raises, the :weather_callsigns_cache process-dict
entry would stick around and poison subsequent unrelated calls on the
same LiveView process. Wrap the building pass in try/after so the key
is always removed.
This commit is contained in:
Graham McIntire 2026-04-21 09:32:17 -05:00
parent 2fc4706d3d
commit c64ad4d571
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -43,16 +43,19 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
weather_set = Aprsme.Packets.weather_callsigns(callsigns)
Process.put(:weather_callsigns_cache, weather_set)
result =
# try/after so the cache is cleared even if packet building raises —
# otherwise a leftover :weather_callsigns_cache entry would poison
# subsequent calls on the same LiveView process.
try do
packets_map
|> Enum.map(fn {_callsign, packet} ->
build_packet_data(packet, is_most_recent, locale)
end)
|> Enum.filter(& &1)
|> deduplicate_by_callsign_group()
Process.delete(:weather_callsigns_cache)
result
after
Process.delete(:weather_callsigns_cache)
end
end
@doc """