From d8ea2b785f9fa334472fc7c87ea67b5d143950d8 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 28 Jul 2025 08:19:27 -0500 Subject: [PATCH] Fix ShutdownHandler health check errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add safe check for ShutdownHandler process existence - Handle case where ShutdownHandler might not be started yet - Prevent GenServer.call errors in health checks - Use Process.whereis and Process.alive? to verify process state This fixes Sentry errors about 'no process' when health checks try to call ShutdownHandler.shutting_down?() 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- lib/aprsme_web/plugs/health_check.ex | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/aprsme_web/plugs/health_check.ex b/lib/aprsme_web/plugs/health_check.ex index ec8dfec..bf3e8c6 100644 --- a/lib/aprsme_web/plugs/health_check.ex +++ b/lib/aprsme_web/plugs/health_check.ex @@ -47,7 +47,7 @@ defmodule AprsmeWeb.Plugs.HealthCheck do health_status == :draining -> {:error, "Application is draining connections"} - Aprsme.ShutdownHandler.shutting_down?() -> + shutting_down?() -> {:error, "Application is shutting down"} true -> @@ -105,4 +105,26 @@ defmodule AprsmeWeb.Plugs.HealthCheck do rescue _ -> {:error, "PubSub check failed"} end + + defp shutting_down? do + # Check if ShutdownHandler process exists and is shutting down + case Process.whereis(Aprsme.ShutdownHandler) do + nil -> + # Process doesn't exist, not shutting down + false + + pid when is_pid(pid) -> + # Process exists, check if alive and call it + if Process.alive?(pid) do + try do + GenServer.call(pid, :shutting_down?, 5000) + catch + :exit, _ -> false + _, _ -> false + end + else + false + end + end + end end