Search code examples
ruby-on-railsherokuunicorn

Setting up Unicorn on Rails 4 - App Crashes


I'm trying to install unicorn on a Rails 4 / Ruby 2.0 app. I set it up using the instructions on heroku here.

I thought the instructions were pretty straightforward but my application at mktdemo.herokuapp.com crashes.

My procfile is being read so on the heroku dashboard, I am seeing unicorn showing up as my server. Is the unicorn.rb as shown on heroku (below) out of date?

In unicorn.rb, there is a ENV[WEB_CONCURRENCY] variable. Do I need to put that in a yml file? I don't see it mentioned anywhere on where that is being read from.

I have delayed_jobs installed on my app so I'm not sure if that has anything to do with it.

#gemfile
gem 'unicorn'

#procfile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work

#config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
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!
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
end

# config/initializers/timeout.rb
Rack::Timeout.timeout = 10  # seconds

Here are the last 50 lines or so in my logs:

←[36m2014-10-23T02:42:30.064512+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializer
s'
←[36m2014-10-23T02:42:30.064346+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/
tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
←[36m2014-10-23T02:42:30.064449+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
←[36m2014-10-23T02:42:30.064465+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
←[36m2014-10-23T02:42:30.064481+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
←[36m2014-10-23T02:42:30.064558+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_m
issing'
←[36m2014-10-23T02:42:30.064427+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
←[36m2014-10-23T02:42:30.064608+00:00 app[web.1]:←[0m   from config.ru:4:in `blo
ck in <main>'
←[36m2014-10-23T02:42:30.064528+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
←[36m2014-10-23T02:42:30.064591+00:00 app[web.1]:←[0m   from config.ru:4:in `req
uire'
←[36m2014-10-23T02:42:30.064496+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
←[36m2014-10-23T02:42:30.064575+00:00 app[web.1]:←[0m   from /app/config/environ
ment.rb:5:in `<top (required)>'
←[36m2014-10-23T02:42:30.064877+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in `build_app!'
←[36m2014-10-23T02:42:30.064790+00:00 app[web.1]:←[0m   from config.ru:1:in `new
'
←[36m2014-10-23T02:42:30.064892+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:137:in `start'
←[36m2014-10-23T02:42:30.064767+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
←[36m2014-10-23T02:42:30.064630+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
←[36m2014-10-23T02:42:30.064924+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
←[36m2014-10-23T02:42:30.064940+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/bin/unicorn:23:in `load'
←[36m2014-10-23T02:42:30.064830+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `eval'
←[36m2014-10-23T02:42:30.064861+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in `call'
←[36m2014-10-23T02:42:30.064956+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/bin/unicorn:23:in `<main>'
←[36m2014-10-23T02:42:30.064814+00:00 app[web.1]:←[0m   from config.ru:1:in `<ma
in>'
←[36m2014-10-23T02:42:30.064846+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `block in builder'
←[36m2014-10-23T02:42:30.897477+00:00 heroku[web.1]:←[0m State changed from star
ting to crashed
←[36m2014-10-23T02:42:30.888021+00:00 heroku[web.1]:←[0m Process exited with sta
tus 1
←[33m2014-10-23T02:44:47.509030+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/" host=mktdemo.herokuapp.com request_id=6472e28
f-4ba3-4eed-aa0d-8089c0ddcec4 fwd="67.180.31.102" dyno= connect= service= status
=503 bytes=
←[33m2014-10-23T02:51:07.861451+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/" host=mktdemo.herokuapp.com request_id=c792113
3-fdbd-4614-8425-c90115aa2251 fwd="74.86.158.106" dyno= connect= service= status
=503 bytes=
←[33m2014-10-23T03:05:42.246318+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/favicon.ico" host=mktdemo.herokuapp.com request
_id=ca8a9d59-9764-4f1c-8b8d-15845c73146e fwd="67.180.31.102" dyno= connect= serv
ice= status=503 bytes=
←[33m2014-10-23T03:05:41.930425+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/" host=mktdemo.herokuapp.com request_id=dd9b869
8-57c5-4465-810e-f55de098df5e fwd="67.180.31.102" dyno= connect= service= status
=503 bytes=

Solution

  • It doesn't look like you've added the rack-timeout gem.

    Add it to your Gemfile:

    gem 'rack-timeout'
    

    Then run bundle install, check in your updated Gemfile and Gemfile.lock, and push the changes up to Heroku.