Reputation: 731
I have looked around for many questions on stackoverflow but have not found a solution yet to my problem.
I was running rails 4.0.2 on heroku with the default webrick server and it was working fine except I would intermittently get these errors:
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)):
And it would bring the whole site down for a significant period of time.
I have read from other answers that there are issues with this with rails 4.0.x so I have upgraded to rails 4.1.4 and will see if the issue continues occurring.
Any help as to what is causing this and how to fix this would be appreciated.
UPDATE
So as per heroku documentation and from what I can find from related questions, I have upgraded my heroku production webserver from webrick to unicorn with the default configurations specified here:
https://devcenter.heroku.com/articles/rails-unicorn
and also here:
https://devcenter.heroku.com/articles/concurrency-and-database-connections
I will watch and see if the issue continues to occur.
Upvotes: 2
Views: 2048
Reputation: 173
This was supposed to fixed in various 4.1.x releases; but it's only actually fixed in 4.2. I had this issue for a long time, and upgrading to rails 4.2 seems to have fixed it, finally!
ActiveRecord::ConnectionTimeoutError - could not obtain a database connection within 5.000 seconds (pool exhaustion) should no longer occur in a properly behaving application as of master / future 4.2.0 (#14360). It's still quite possible to exhaust your pool if you have more threads than connections, and those threads are hanging on to the connections for too long.
https://github.com/rails/rails/issues/12867
Upvotes: 1