Skip to content

Commit

Permalink
show error message when replication connection failed to establish a …
Browse files Browse the repository at this point in the history
…connection
  • Loading branch information
DohanKim committed Jan 22, 2025
1 parent bca9131 commit 5afa8c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/postgrex/replication_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ defmodule Postgrex.ReplicationConnection do
maybe_handle(mod, :handle_connect, [mod_state], %{s | protocol: protocol})

{:error, reason} ->
Logger.error(
"#{inspect(pid_or_name())} (#{inspect(mod)}) failed to connect to Postgres: #{Exception.format(:error, reason)}"
)

if s.auto_reconnect do
{:keep_state, s, {{:timeout, :backoff}, s.reconnect_backoff, nil}}
else
Expand Down
11 changes: 11 additions & 0 deletions lib/postgrex/simple_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ defmodule Postgrex.SimpleConnection do
end

{:error, reason} ->
Logger.error(
"#{inspect(pid_or_name())} (#{inspect(mod)}) failed to connect to Postgres: #{Exception.format(:error, reason)}"
)

if state.auto_reconnect do
{:keep_state, state, {{:timeout, :backoff}, state.reconnect_backoff, nil}}
else
Expand Down Expand Up @@ -466,6 +470,13 @@ defmodule Postgrex.SimpleConnection do
end
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(mod), do: Process.get(mod)

defp put_opts(mod, opts), do: Process.put(mod, opts)
Expand Down

0 comments on commit 5afa8c9

Please sign in to comment.