Search code examples
ruby-on-railsdeploymentherokuproduction-environmentunicorn

Issue with Unicorn Deploy to Heroku - production environment issues only


I'm having problems deploying to Heroku. Everything works fine on my development machine (I'm using Foreman/Unicorn to run the web worker and background DelayedJob process). However when I try to run in Production on Heroku, I get strange errors about logger...

app error: undefined method `tagged' for #<Logger:0x00000005aee368> (NoMethodError)
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/rack/logger.rb:14:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.1/lib/action_dispatch/middleware/static.rb:53:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:132:in `forward'
/app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:241:in `fetch'
/app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:181:in `lookup'
/app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:65:in `call!'
/app/vendor/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:50:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/engine.rb:479:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/application.rb:220:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:530:in `process_client'
/app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:604:in `worker_loop'
/app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:487:in `spawn_missing_workers'
/app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:137:in `start'
/app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/bin/unicorn:121:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/unicorn:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/unicorn:19:in `<main>'

The confusing part is that it the error trace is all gem code... maybe something wrong with my unicorn / proc file?

Unicorn:

worker_processes 3 # amount of unicorn workers to spin up
preload_app true
timeout 30         # restarts workers that hang for 30 seconds

@delayedjob_pid = nil

before_fork do |server, worker|
  @delayedjob_pid ||= spawn("bundle exec rake environment jobs:work QUEUE=immediate")
end

after_fork do |server, worker|
  ActiveRecord::Base.establish_connection
end

Proc:

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

I can post whatever else would be useful!!! Thanks in advance...


Solution

  • Turns out that Heroku does not currently get along well with Rails 3.2, and custom logging.

    What fixed my issue - comment out the following:

     #config.log_tags = [:uuid, :remote_ip]
    

    See also http://broadcastingadam.com/2012/01/rails320_heroku_and_rails_log_stdout