Fix ShutdownHandler health check errors

- 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 <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-07-28 08:19:27 -05:00
parent afaf5730a3
commit d8ea2b785f
No known key found for this signature in database

View file

@ -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