我在生产环境中使用自定义域在 Heroku 上部署了一个 Rails 4 应用程序。我也有一个暂存版本。该应用程序使用 Comfortable Mexican Sofa。
出现以下问题:应用程序将达到所有请求都返回 500 错误的状态。日志显示:
[jesse@Athens expat]$ heroku logs
ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)):
[jesse@Athens expat]$ heroku pg:info
Connections: 5
[jesse@Athens expat]$ heroku pg:ps
pid | state | source | running_for | waiting | query
-----+-------+--------+-------------+---------+-------
(0 rows)
[jesse@Athens expat]$ heroku pg:killall
pg_terminate_backend
----------------------
t
t
t
t
t
(5 rows)
随后的连接尝试导致 500 错误并且数据库连接保持为 0。
在我使用本指南创建自定义错误页面后出现了这个问题:http://wearestac.com/blog/dynamic-error-pages-in-rails .
我可以通过创建一个使用数据库的 404 页面然后向服务器发出大约 5 或 6 个请求来获取不存在的页面来强制解决这个问题。
编辑:
在使用静态自定义 404 页面时,我可以通过发出 5 或 6 个对不存在的带有 jpeg 扩展名的文件的请求来强制解决这个问题。日志中出现以下内容:
Error during failsafe response: Missing template errors/not_found, application/not_found with {:locale=>[:en], :formats=>[:jpeg], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee, :haml]}. Searched in:
2014-02-17T17:26:14.595469+00:00 app[web.1]: * "/app/app/vi
ews"
2014-02-17T17:26:14.594508+00:00 app[web.1]: Completed 500 Internal Server Error in 7ms
如能帮助解决此问题,我们将不胜感激。提前致谢
最佳答案
这是功能 Controller 代码:
class ErrorsController < ApplicationController
def not_found
respond_to do |format|
format.any(:htm, :html, :xls, :xlsx) { render :status => 404, :layout => "error_frame", :formats => [:html] }
format.all { render nothing: true, status: 404 }
end
end
def unacceptable
respond_to do |format|
format.html { render :status => 422, :layout => "error_frame" }
format.all { render nothing: true, status: 422 }
end
end
def internal_error
respond_to do |format|
format.html { render :layout => false, :status => 500 }
format.all { render nothing: true, status: 500}
end
end
end
关于ruby-on-rails - Rails 4 自定义 404 导致 Heroku 上的 postgresql 连接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21834377/