Skip to content

Include pool label in closed connection errors - #363

Open
agustin2606 wants to merge 1 commit into
elixir-ecto:masterfrom
agustin2606:label-in-closed-connection-error
Open

agustin2606 wants to merge 1 commit into
elixir-ecto:masterfrom
agustin2606:label-in-closed-connection-error

Conversation

@agustin2606

Copy link
Copy Markdown

Fixes #346

When a pool is started with :label (as ecto_sql does with the repo name since elixir-ecto/ecto_sql#698), the "connection is closed" error now says which pool it came from.

Problem

With several repos, an ownership timeout in tests surfaces as an error that doesn't say which repo it belongs to.

Ecto.Adapters.SQL.Sandbox.checkout(Repo, ownership_timeout: 100)

Repo.transact(fn ->
  Process.sleep(200)
  Repo.insert_all("dogs", [%{name: "Barkley"}])
end)
# before: ** (DBConnection.ConnectionError) connection is closed because of an error, disconnect or timeout
# after:  ** (DBConnection.ConnectionError) [MyApp.Repo] connection is closed because of an error, disconnect or timeout

Cause

The error is built in the caller by DBConnection.Holder after the ownership proxy has stopped and its holder table is gone, so there is no live process left whose label could be read (the approach #332 used for OwnershipError).

Fix

  • The connection stores its :label in the holder's conn record when it checks in. Holder.checkout already reads that record, so it copies the label into the pool_ref. The ownership proxy passes the label of the connection it checked out on to its own holder.
  • Both "connection is closed because of an error, disconnect or timeout" errors get a [inspect(label)] prefix, written with inspect like the label in the ownership error (Ownership.Manager).
  • Without :label the message is unchanged. No process labels are involved, so it works on every supported OTP version.

Testing

  • Ownership timeout with label: TestRepo: the error message is prefixed with [TestRepo].
  • The same scenario without a label keeps the exact current message.

@josevalim

Copy link
Copy Markdown
Member

@nathanl did we discuss this before as well? The concern with this approach is additional data copying into the holder on every operation. I wonder if this could be lifted from the process instead (or not because the process may be dead).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Repo name to timeout errors

2 participants