Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to fix binary memory leak in ETS flusher #200

Merged
merged 1 commit into from
May 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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