I have a fairly straightforward application which is running without problem locally, but when deployed to heroku it quickly stops working with a 500 error and the following error in the logs:
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.003 seconds))
I have had a search around and found this question which appears to be very similar. I don't really understand from that question what the relevance of the requests for jpeg files are, and I don't understand what the probelm is from the answer given. I can recreate by restarting the server then calling a page which returns a 404 several times.
I have the same results as mentioned in the question (specifically Connections < DB_POOL):
(staging) $ heroku pg:info --remote staging
=== HEROKU_POSTGRESQL_ONYX_URL (DATABASE_URL)
Plan: Hobby-dev
Status: Available
Connections: 5
PG Version: 9.3.4
Created: 2014-05-02 08:57 UTC
Data Size: 9.9 MB
Tables: 11
Rows: 6508/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
(staging) $ heroku config
.....
DB_POOL: 10
.....
I developed my solution based on this railscast which seems the same approach as in the other question. I do not however understand the answer provided in this other question and how it might apply to mine solution as follows: routes.rb:
match ':status', to: 'errors#show', constraints: {status: /\d{3}/ }, via: :all
application.rb:
config.exceptions_app = self.routes
errorscontroller.rb
class ErrorsController < ApplicationController
def show
status = request.path[1..-1]
case status
when "404"
@error = "404 - The page you were looking for cannot be found"
when "403"
@error = "403 - The page you were looking for is not accessible"
when "500"
@error = "500 - An error occurred within the server"
end
respond_to do |format|
format.html { render action: "error" }
format.json { render json: {status: status, error: @exception.message} }
end
end
end
error.html.erb
<div class='container'>
<h1 class="errorh1">Oops something went wrong!!</h1>
<h2 class="errorh2"><%= @error %></h2>
<br>
<p>We are sorry. Please <a href='#' data-uv-trigger="contact
">let us know</a> what you were trying to do so that we can look into the problem.</p>
<br>
<p>When you are ready to continue, <a href="/">go home</a> to start again.</p>
</div>
Note: I am running Rails 4.0.4 (and psql (PostgreSQL) 9.3.4 locally)