Rails could offer a better output when encountering "Could not obtain a connection"?

I’m wondering if Rails should offer more detailed information about why we see so many connections when encountering the infamous:

ActiveRecord::ConnectionTimeoutError ‘Could not obtain a connection from the pool within 5.000 seconds.’

Short snippet extracted from a blog post:

Bugsnag.configure do |config|
  config.add_on_error(proc do |event|
    if event.errors.first.error_class == "ActiveRecord::ConnectionTimeoutError"
      connection_pool_info = ActiveRecord::Base.connection_pool.connections.map do |connection|
        connection.owner.present? ? connection.owner.inspect : "[UNUSED]"
      end.join("\n")

      event.add_metadata(:app, :connection_pool_info, connection_pool_info)
    end
  end
end

We could imagine having the sum of connections used by “type” of connection.owner.

could not obtain a connection from the pool within 5.000 seconds (waited 5.403 seconds);
all pooled connections were in use. 3 by Puma::ThreadPool, 7 by ActionController::Metal::Live.

Related:

2 Likes