From b55ec785d5238b3e47b73b1f6ef7747596877fcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 7 Aug 2024 19:06:21 +0200 Subject: [PATCH] Log error message if Postgrex.ReplicationConnection is reconnecting --- lib/postgrex/replication_connection.ex | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/postgrex/replication_connection.ex b/lib/postgrex/replication_connection.ex index 11c21613..ee73f917 100644 --- a/lib/postgrex/replication_connection.ex +++ b/lib/postgrex/replication_connection.ex @@ -611,13 +611,25 @@ defmodule Postgrex.ReplicationConnection do {:stop, reason, s} end - defp reconnect_or_stop(error, _reason, _protocol, %{auto_reconnect: true} = s) + defp reconnect_or_stop(error, reason, _protocol, %{auto_reconnect: true} = s) when error in [:error, :disconnect] do %{state: {mod, mod_state}} = s + + Logger.error( + "#{inspect(pid_or_name())} (#{inspect(mod)}) is reconnecting due to reason: #{Exception.format(:error, reason)}" + ) + {:keep_state, s} = maybe_handle(mod, :handle_disconnect, [mod_state], s) {:keep_state, %{s | streaming: nil}, {:next_event, :internal, {:connect, :reconnect}}} end + defp pid_or_name do + case Process.info(self(), :registered_name) do + {:registered_name, atom} when is_atom(atom) -> atom + _ -> self() + end + end + defp opts(), do: Process.get(__MODULE__) defp put_opts(opts), do: Process.put(__MODULE__, opts) end