Skip to content

Commit

Permalink
Attempting to fix binary memory leak in ETS flusher (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
akoutmos authored May 7, 2023
1 parent 6a002fb commit b80c52e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/prom_ex/ets_cron_flusher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule PromEx.ETSCronFlusher do

use GenServer

@flush_timeout 10_000

@doc """
Used to start the `PromEx.ETSCronFlusher` process.
"""
Expand Down Expand Up @@ -48,7 +50,15 @@ defmodule PromEx.ETSCronFlusher do

@impl true
def handle_info(:flush_ets, state) do
PromEx.get_metrics(state.prom_ex_module)
# In order to avoid leaking large binaries of metrics, the flush should take place
# inside of an ephemeral task so that the heap memory is reclaimed when the process
# dies
flush_task =
Task.async(fn ->
PromEx.get_metrics(state.prom_ex_module)
end)

Task.await(flush_task, @flush_timeout)

timer_ref = schedule_flush(state)
{:noreply, %{state | timer_ref: timer_ref}}
Expand Down

0 comments on commit b80c52e

Please sign in to comment.