From b0d811bdd4b1b5643214881fa74ef821d64fd307 Mon Sep 17 00:00:00 2001 From: Stefano Gessa Date: Sun, 15 Jun 2025 18:17:24 +0700 Subject: [PATCH] Handle errors in `Harvest.HarvestCycle.send_harvest/2` --- .gitignore | 1 + lib/new_relic/harvest/harvest_cycle.ex | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ae4c7c37..4048883b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ erl_crash.dump tmp config/secret.exs .DS_Store +.tool-versions diff --git a/lib/new_relic/harvest/harvest_cycle.ex b/lib/new_relic/harvest/harvest_cycle.ex index a27818d6..34e1c84e 100644 --- a/lib/new_relic/harvest/harvest_cycle.ex +++ b/lib/new_relic/harvest/harvest_cycle.ex @@ -131,13 +131,22 @@ defmodule NewRelic.Harvest.HarvestCycle do :exit, _exit -> NewRelic.log(:error, "Failed to send harvest from #{inspect(supervisor)}") after - DynamicSupervisor.terminate_child(supervisor, harvester) + terminate_child(supervisor, harvester) end end, shutdown: @harvest_timeout ) end + defp terminate_child(supervisor, harvester) do + try do + DynamicSupervisor.terminate_child(supervisor, harvester) + catch + :exit, _exit -> + :ok + end + end + defp stop_harvest_cycle(timer), do: timer && Process.cancel_timer(timer) defp trigger_harvest_cycle(%{