2

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.

3
  • Could possibly be running out of connections in your connection pool? Have you tried to increase that? devcenter.heroku.com/articles/… Commented Jul 30, 2014 at 7:11
  • Also, is there any common query/activity happening around this error in your logs? Commented Jul 30, 2014 at 7:13
  • Related github.com/rails/rails/issues/12867#issuecomment-46740419 Commented Jul 30, 2014 at 7:59

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

same problem here as Harry. upgraded first to rails 41. as some were suggesting it solved pb but still getting the same error. If I upgrade and put on my gemfile gem 'rails', "~> 4.2.0", i hope to solve the issue!
back after 15 days:) yes upgrading to rails 4.2 solved the issue!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.