title: What can I do about unicorn::clientshutdown errors on my heroku rails app?
body: <p>I have an app that accepts image uploads. It's a rails 3 app on heroku using Unicorn. I'm occasionally getting <code>unicorn::clientshutdown</code> exceptions, and I don't really know what causes them or how to handle them. What should I do?</p>
  
  <p>This is my <code>unicorn.rb</code> file:</p>
  
  <pre><code>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
  </code></pre>