Skip to content

Commit

Permalink
Log error message if Postgrex.ReplicationConnection is reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 7, 2024
1 parent 66a4682 commit b55ec78
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/postgrex/replication_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b55ec78

Please sign in to comment.