Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/postgrex/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -801,10 +801,7 @@ defmodule Postgrex.Protocol do
pid: pid,
timeout: timeout
},
report_cb: fn %{source: {module, _}} = report ->
{"~ts (~tw) timed out because it was handshaking for longer than ~twms",
[inspect(module), report.pid, report.timeout]}
end
report_cb: &__MODULE__._format_handshake_shutdown/1
)

:gen_tcp.shutdown(sock, :read_write)
Expand All @@ -818,6 +815,12 @@ defmodule Postgrex.Protocol do
:ok
end

@doc false
def _format_handshake_shutdown(%{source: {module, _}} = report) do
{"~ts (~tw) timed out because it was handshaking for longer than ~twms",
[inspect(module), report.pid, report.timeout]}
end

defp do_handshake(_host, s, %{ssl: nil} = status), do: startup(s, status)

defp do_handshake(host, s, %{ssl: ssl_opts} = status) do
Expand Down
37 changes: 21 additions & 16 deletions lib/postgrex/replication_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,7 @@ defmodule Postgrex.ReplicationConnection do
mod: mod,
reason: reason
},
report_cb: fn report ->
{"~ts (~ts) failed to connect to Postgres: ~ts",
[
inspect(report.pid_or_name),
inspect(report.mod),
Exception.format(:error, report.reason)
]}
end
report_cb: &__MODULE__._format_connection_error/1
)

if s.auto_reconnect do
Expand Down Expand Up @@ -565,6 +558,25 @@ defmodule Postgrex.ReplicationConnection do
end

## Helpers
@doc false
def _format_connection_error(report) do
{"~ts (~ts) failed to connect to Postgres: ~ts",
[
inspect(report.pid_or_name),
inspect(report.mod),
Exception.format(:error, report.reason)
]}
end

@doc false
def _format_reconnect_error(report) do
{"~ts (~ts) is reconnecting due to reason: ~ts",
[
inspect(report.pid_or_name),
inspect(report.mod),
Exception.format(:error, report.reason)
]}
end

defp handle_data([], s), do: {:keep_state, s}

Expand Down Expand Up @@ -674,14 +686,7 @@ defmodule Postgrex.ReplicationConnection do
mod: mod,
reason: reason
},
report_cb: fn report ->
{"~ts (~ts) is reconnecting due to reason: ~ts",
[
inspect(report.pid_or_name),
inspect(report.mod),
Exception.format(:error, report.reason)
]}
end
report_cb: &__MODULE__._format_reconnect_error/1
)

{:keep_state, s} = maybe_handle(mod, :handle_disconnect, [mod_state], s)
Expand Down
19 changes: 11 additions & 8 deletions lib/postgrex/simple_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,7 @@ defmodule Postgrex.SimpleConnection do
mod: mod,
reason: reason
},
report_cb: fn report ->
{"~ts (~ts) failed to connect to Postgres: ~ts",
[
inspect(report.pid_or_name),
inspect(report.mod),
Exception.format(:error, report.reason)
]}
end
report_cb: &__MODULE__._format_connection_error/1
)

if state.auto_reconnect do
Expand Down Expand Up @@ -441,6 +434,16 @@ defmodule Postgrex.SimpleConnection do

## Helpers

@doc false
Comment thread
josevalim marked this conversation as resolved.
def _format_connection_error(report) do
{"~ts (~ts) failed to connect to Postgres: ~ts",
[
inspect(report.pid_or_name),
inspect(report.mod),
Exception.format(:error, report.reason)
]}
end

defp maybe_handle(mod, fun, args, state) do
if function_exported?(mod, fun, length(args)) do
handle(mod, fun, args, nil, state)
Expand Down
Loading