Heroku,resque,unicorn - '[COBALT]无法从客户端接收数据:连接由同行重置'。

时间:2013-10-21 17:09:00

标签: ruby-on-rails resque unicorn

有什么想法在日志中导致此消息?

'[COBALT] could not receive data from client: Connection reset by peer'. 

我认为这是before_fork / after_fork过程中的一个问题 - 或者只是与此代码无关的Heroku问题?

resque.rb

require 'resque/server'

ENV["REDIS_URL"] ||= "redis://localhost:6379/"

uri          = URI.parse(ENV["REDIS_URL"])
$redis       = Redis.new(host: uri.host, port: uri.port, password: uri.password)
Resque.redis = $redis

Resque.after_fork = Proc.new { ActiveRecord::Base.establish_connection }

unicorn.rb

# config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 20
preload_app true

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

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!

  if defined?(Resque)
    Resque.redis.quit
    Rails.logger.info('Disconnected from Redis')
  end

end

after_fork do |server, worker|

  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection

  if defined?(Resque)
    Resque.redis = ENV['REDIS_URL']
    Rails.logger.info('Connected to Redis')
  end

end

0 个答案:

没有答案