簡體   English   中英

關於我的heroku rails app上的unicorn :: clientshutdown錯誤,我該怎么辦?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM