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:
parent
afaf5730a3
commit
d8ea2b785f
1 changed files with 23 additions and 1 deletions
|
|
@ -47,7 +47,7 @@ defmodule AprsmeWeb.Plugs.HealthCheck do
|
||||||
health_status == :draining ->
|
health_status == :draining ->
|
||||||
{:error, "Application is draining connections"}
|
{:error, "Application is draining connections"}
|
||||||
|
|
||||||
Aprsme.ShutdownHandler.shutting_down?() ->
|
shutting_down?() ->
|
||||||
{:error, "Application is shutting down"}
|
{:error, "Application is shutting down"}
|
||||||
|
|
||||||
true ->
|
true ->
|
||||||
|
|
@ -105,4 +105,26 @@ defmodule AprsmeWeb.Plugs.HealthCheck do
|
||||||
rescue
|
rescue
|
||||||
_ -> {:error, "PubSub check failed"}
|
_ -> {:error, "PubSub check failed"}
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue