Skip to content

Print repo name in connection pool errors#334

Merged
josevalim merged 5 commits into
elixir-ecto:masterfrom
guisehn:print-repo-name-in-connection-pool-errors
Oct 30, 2025
Merged

Print repo name in connection pool errors#334
josevalim merged 5 commits into
elixir-ecto:masterfrom
guisehn:print-repo-name-in-connection-pool-errors

Conversation

@guisehn

@guisehn guisehn commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

Adds the pool name to connection pool errors, helping to find the database with problems when an application uses multiple repos:

  ** (EXIT from #PID<0.933.0>) shell process exited with reason: an exception was raised:
-     ** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 4324ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:
+     ** (DBConnection.ConnectionError) [Elixir.MyApp.Repo] connection not available and request was dropped from queue after 4324ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:

    1. Ensuring your database is available and that you can connect to it
    2. Tracking down slow queries and making sure they are running fast enough
    3. Increasing the pool_size (although this increases resource consumption)
    4. Allowing requests to wait longer by increasing :queue_target and :queue_interval

  See DBConnection.start_link/2 for more information

          (db_connection 2.8.1) lib/db_connection.ex:986: DBConnection.run/3
          (elixir 1.15.7) src/elixir.erl:396: :elixir.eval_external_handler/3
          (stdlib 5.1.1) erl_eval.erl:750: :erl_eval.do_apply/7
          (stdlib 5.1.1) erl_eval.erl:136: :erl_eval.exprs/6
          (elixir 1.15.7) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2

Solves #333

@guisehn guisehn marked this pull request as draft October 29, 2025 23:05
@guisehn guisehn marked this pull request as ready for review October 29, 2025 23:23
@josevalim

Copy link
Copy Markdown
Member

Hi @guisehn I would prefer to not depend on repo, because it is really not a db_connection configuration or concern. Looking at the connection pool, maybe you can rely on $ancestors?

Something like this:

List.first(Process.get(:"$ancestors, []))

Or perhaps this:

Enum.find(Process.get(:"$ancestors, []), &is_atom/1)

This would also simplify the PR as you won't need to pass all state around. Thanks!

@guisehn

guisehn commented Oct 30, 2025

Copy link
Copy Markdown
Contributor Author

@josevalim nice trick! Touching all the function signatures was really giving me the creeps. :)

Implemented on 343dec5

@josevalim josevalim merged commit 33f67eb into elixir-ecto:master Oct 30, 2025
2 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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.

2 participants