Home > Mobile >  Getting intermittent error of "No connection pool for 'ActiveRecord::Base' found"
Getting intermittent error of "No connection pool for 'ActiveRecord::Base' found"

Time:07-29

Rails 7.0.3.1, Ruby 3.1.2, pg gem 1.3.5, puma gem 4.3.12.

All hosting is in Azure. Web app is running in AKS, with a Postgres instance running on a General Purpose compute machine.

We're running into intermittent errors of "No connection pool for 'ActiveRecord::Base' found" when running the app, on actions which cause a DB connection. This was especially apparent when we ran a light stress test: once there were sufficient connections, almost all requests began experiencing this error. Not surprising, if the issue is that the maximum number of connections had been reached.

However, this seems like a far, far smaller number of connections than we should begin seeing problems at. Further, I'd expect to see 'Connection timeout' messages rather than 'No connection pool available'. This leads me to think we have a misconfiguration somewhere.

Entry for this environment in database.yml looks as follows:

[env]:
  adapter: postgresql
  encoding: utf8
  pool: 100
  database: <%= [Value from ENV] %>
  username: <%= [Value from ENV] %>
  password: <%= [Value from ENV] %>
  host: <%= [Value from ENV] %>
  sslmode: require

There's no puma.rb configuration file present, so I assume we're using the default values for everything there.

Any help or suggestions are very welcome.

CodePudding user response:

Answer turned out to be something unexpected.

We're hosted in Kubernetes, and have both health and liveness endpoints.

Turned out in the liveness endpoint, we were calling ActiveRecord::Base.establish_connection which was apparently destroying the old DB connection pool and creating another.

Answer/solution was found here: https://stackoverflow.com/a/66928112/3439498

  • Related