90

unicorn と sidekiq を実行している Heroku アプリで R12 Exit Timeout エラーが発生します。これらのエラーは、1 日に 1 ~ 2 回、デプロイするたびに発生します。ユニコーンが正しく応答するには、Heroku からのシャットダウン信号を変換する必要があることは理解していますが、以下のユニコーン構成で変換したと思います。

worker_processes 3
timeout 30
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts "Unicorn master intercepting TERM and sending myself QUIT instead. My PID is #{Process.pid}"
    Process.kill 'QUIT', Process.pid
  end

  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
    Rails.logger.info('Disconnected from ActiveRecord')
  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. My PID is #{Process.pid}"
  end

  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
    Rails.logger.info('Connected to ActiveRecord')
  end

  Sidekiq.configure_client do |config|
    config.redis = { :size => 1 }
  end
end

エラーに関するログは次のようになります。

Stopping all processes with SIGTERM
Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT. My PID is 7
Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT. My PID is 11
Unicorn worker intercepting TERM and doing nothing. Wait for master to sent QUIT. My PID is 15
Unicorn master intercepting TERM and sending myself QUIT instead. My PID is 2
Started GET "/manage"
reaped #<Process::Status: pid 11 exit 0> worker=1
reaped #<Process::Status: pid 7 exit 0> worker=0
reaped #<Process::Status: pid 15 exit 0> worker=2
master complete
Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM
Stopping remaining processes with SIGKILL
Process exited with status 137

タイムアウト前にすべての子プロセスが正常にリープされたようです。マスターがまだ生きている可能性はありますか?また、ログに示されているように、ルーターはシャットダウン中に Web 要求を引き続き dyno に送信する必要がありますか?

FWIW、私は Heroku のゼロ ダウンタイム デプロイメント プラグイン ( https://devcenter.heroku.com/articles/labs-preboot/ ) を使用しています。

4

1 に答える 1