Ahmed
Ahmed

Reputation: 809

Unicorn undefined method error in production

I'm running a Ruby on Rails application on Heroku using Rails 4.1.4, Unicorn 4.8.3 and Ruby 2.1.1. I've tried to keep the development and production environments similar. In development, Unicorn runs just fine.

In production I get this in the logs:

» 21:54:50.942 2014-08-08 01:54:50.645897+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:651:in `worker_loop'
» 21:54:50.942 2014-08-08 01:54:50.645898+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
» 21:54:50.947 2014-08-08 01:54:50.645900+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:536:in `maintain_worker_count'
» 21:54:50.947 2014-08-08 01:54:50.645902+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:294:in `join'
» 21:54:50.947 2014-08-08 01:54:50.645904+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
» 21:54:50.947 2014-08-08 01:54:50.645905+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `load'
» 21:54:50.947 2014-08-08 01:54:50.645907+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `<main>'
» 21:54:50.947 2014-08-08 01:54:50.706442+00:00 app web.2 - - E, [2014-08-08T01:54:50.705828 #609] ERROR -- : undefined method `[]=' for nil:NilClass (NoMethodError)
» 21:54:50.947 2014-08-08 01:54:50.706451+00:00 app web.2 - - ./config/unicorn.rb:24:in `block in reload'
» 21:54:50.947 2014-08-08 01:54:50.706454+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:622:in `call'
» 21:54:50.958 2014-08-08 01:54:48.473529+00:00 heroku web.1 - - Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM Warning
» 21:54:50.971 2014-08-08 01:54:50.665188+00:00 app web.1 - - E, [2014-08-08T01:54:50.665105 #2] ERROR -- : reaped #<Process::Status: pid 487 exit 1> worker=0
» 21:54:50.973 2014-08-08 01:54:50.722566+00:00 app web.1 - - E, [2014-08-08T01:54:50.722003 #495] ERROR -- : undefined method `[]=' for nil:NilClass (NoMethodError)
» 21:54:50.973 2014-08-08 01:54:50.722572+00:00 app web.1 - - ./config/unicorn.rb:24:in `block in reload'
» 21:54:50.973 2014-08-08 01:54:50.722574+00:00 app web.1 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:622:in `call'
» 21:54:50.973 2014-08-08 01:54:50.722576+00:00 app web.1 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:622:in `init_worker_process'

The app pretty much doesn't start. I've searched for the undefined method `[]=' for nil:NilClass (NoMethodError) error in Google and here -- nothing helpful came up.

Any ideas?

Upvotes: 1

Views: 1831

Answers (1)

Ahmed
Ahmed

Reputation: 809

I was able to fix this by updating part of the unicorn.rb configuration file.

From:

config = Rails.application.config.database_configuration[Rails.env]

To:

config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env]

I was using outdated code. Source

Upvotes: 3

Related Questions