Skip to content
Open
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
26 changes: 22 additions & 4 deletions lib/db_connection/holder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,43 @@ defmodule DBConnection.Holder do
:ets.lookup(holder, :conn)
rescue
ArgumentError ->
msg = "connection is closed because of an error, disconnect or timeout"
msg =
maybe_prefix_repo(
"connection is closed because of an error, disconnect or timeout",
opts
)

{:disconnect, DBConnection.ConnectionError.exception(msg), _state = :unused}
else
[conn(lock: conn_lock)] when conn_lock != lock ->
raise "an outdated connection has been given to DBConnection on #{fun}/#{length(args) + 2}"
raise maybe_prefix_repo(
"an outdated connection has been given to DBConnection on #{fun}/#{length(args) + 2}",
opts,
":"
)

[conn(status: :error)] ->
msg = "connection is closed because of an error, disconnect or timeout"
msg =
maybe_prefix_repo(
"connection is closed because of an error, disconnect or timeout",
opts
)

{:disconnect, DBConnection.ConnectionError.exception(msg), _state = :unused}

[conn(status: :aborted)] when type != :cleanup ->
msg = "transaction rolling back"
msg = maybe_prefix_repo("transaction rolling back", opts)
{:disconnect, DBConnection.ConnectionError.exception(msg), _state = :unused}

[conn(module: module, state: state)] ->
holder_apply(holder, module, fun, args ++ [opts, state])
end
end

defp maybe_prefix_repo(msg, opts, separator \\ "") do
if opts[:repo], do: "#{inspect(opts[:repo])} " <> separator <> msg, else: msg
end

## Pool state helpers API (invoked by callers)

@spec put_state(pool_ref :: any, term) :: :ok
Expand Down
11 changes: 7 additions & 4 deletions lib/db_connection/ownership/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ defmodule DBConnection.Ownership.Manager do
mode: mode,
mode_ref: nil,
ets: ets,
log: log
log: log,
repo: pool_opts[:repo]
}}
end

Expand Down Expand Up @@ -223,7 +224,7 @@ defmodule DBConnection.Ownership.Manager do
{:noreply, state}

:not_found when mode == :manual ->
not_found(from, mode)
not_found(from, mode, state.repo)
{:noreply, state}

:not_found ->
Expand Down Expand Up @@ -393,10 +394,12 @@ defmodule DBConnection.Ownership.Manager do
caller
end

defp not_found({pid, _} = from, mode) do
defp not_found({pid, _} = from, mode, repo) do
msg = """
cannot find ownership process for #{Util.inspect_pid(pid)}
using mode #{inspect(mode)}.
using mode #{inspect(mode)} on repo #{inspect(repo)}.
(Note that a connection's mode reverts to :manual if its owner
terminates.)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on line 381


When using ownership, you must manage connections in one
of the four ways:
Expand Down
Loading