[英]What can I do about unicorn::clientshutdown errors on my heroku rails app?
我有一个接受图片上传的应用程序。 这是使用Unicorn的heroku上的rails 3应用程序。 我偶尔会得到unicorn::clientshutdown
例外,我真的不知道是什么原因导致它们或如何处理它们。 我该怎么办?
这是我的unicorn.rb
文件:
before_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
# If you are using Redis but not Resque, change this
if defined?(Resque)
Resque.redis.quit
Rails.logger.info('Disconnected from Redis')
end
end
after_fork do |server, worker|
# Replace with MongoDB or whatever
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
# If you are using Redis but not Resque, change this
if defined?(Resque)
Resque.redis = ENV['REDIS_URI']
Rails.logger.info('Connected to Redis')
end
end
图片上传,Heroku和Unicorn,哦,我的。
问题
这是此错误的三连胜。 您的Heroku日志中可能存在相关的H12错误( https://devcenter.heroku.com/articles/error-codes#h12-request-timeout )。 发生的事情是请求花了太长时间才完成(Heroku有一个不可避免的30秒超时),所以它断开连接并且那个独角兽工人被杀了。 此外,对于慢速/长时间运行的请求,Unicorn不是很好(参见http://rainbows.rubyforge.org )
解
诀窍是在前端上传图像而不点击服务器(CORS / AJAX / jquery.fileupload.js / etc),将上传的文件位置与表单提交一起传递,然后再作为后台作业执行任何处理和重新上载,不受30秒超时限制。 其他人则对此进行了更广泛的撰写。 此外,您可以使用Cloudinary等服务为您执行此操作。
PS
YMMV,但你也应该将它添加到你的独角兽配置中( https://devcenter.heroku.com/articles/rails-unicorn )
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
# ...
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT'
end
# ...
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.