Search code examples
ruby-on-railsnginxamazon-ec2thin

thin web server generates error uninitialized constant ActiveSupport::Dependencies when servicing request


I've been stuck on this for a bit and have read the Thin forum, googled everything I can think of, tried to see if I've using the wrong gem versions, so I hope someone can suggest how I can debug this problem.

I start Thin with this command line:

 thin start -C /root/myapp/config/thin.yml -e production -d --adapter rack 

I'm running nginx with the Thin web server on Amazon's EC2 with Rails 3.0.3 and Ruby 1.9.2-p290. Nginx and Thin run fine, but when an HTTP request is sent to Thin from nginx, Thin kicks out the following error and Nginx reqports "502 Bad Gateway":

 !! Unexpected error while processing request: uninitialized constant      ActiveSupport::Dependencies
 uninitialized constant ActiveSupport::Dependencies
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:9:in `initialize'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:67:in `new'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.3/lib/action_dispatch/middleware/stack.rb:67:in `use'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.3/lib/rails/application.rb:190:in `block in default_middleware_stack'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.3/lib/rails/application.rb:189:in `tap'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.3/lib/rails/application.rb:189:in `default_middleware_stack'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.3/lib/rails/application.rb:161:in `app'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.3/lib/rails/application.rb:168:in `call'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/connection.rb:76:in `block in pre_process'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/connection.rb:74:in `catch'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/connection.rb:74:in `pre_process'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/connection.rb:57:in `process'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/connection.rb:42:in `receive_data'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/backends/base.rb:57:in `start'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/server.rb:156:in `start'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/controllers/controller.rb:80:in `start'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/runner.rb:177:in `run_command'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/lib/thin/runner.rb:143:in `run!'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/thin-1.2.7/bin/thin:6:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.2-p290/bin/thin:19:in `load'
/usr/local/rvm/gems/ruby-1.9.2-p290/bin/thin:19:in `<main>'

Here is my gem list:

* LOCAL GEMS *

 abstract (1.0.0)
 actionmailer (3.0.3)
 actionpack (3.0.3)
 activemodel (3.0.3)
 activerecord (3.0.3)
 activeresource (3.0.3)
 activesupport (3.0.3)
 arel (2.0.10)
 builder (2.1.2)
 bundler (1.0.10 ruby)
 cgi_multipart_eof_fix (2.5.0)
 daemons (1.0.10)
 erubis (2.6.6)
 eventmachine (0.12.10)
 fastthread (1.0.7)
 gem_plugin (0.2.3)
 i18n (0.6.0)
 mail (2.2.19)
 mime-types (1.17.2)
 mongrel (1.2.0.pre2)
 multi_json (1.0.4)
 mysql2 (0.2.18, 0.2.17)
 polyglot (0.3.3)
 rack (1.2.5, 1.2.4)
 rack-cache (1.0)
 rack-mount (0.6.14)
 rack-test (0.5.7)
 rails (3.0.3)
 railties (3.0.3)
 rake (0.9.2.2)
 redis (2.2.2)
 redis-namespace (1.0.3)
 resque (1.19.0)
 resque-access_worker_from_job (0.3.1)
 rmagick (2.13.1)
 sinatra (1.2.8)
 thin (1.2.7)
 thor (0.14.6)
 tilt (1.3.3)
 treetop (1.4.10)
 tzinfo (0.3.31)
 vegas (0.1.8)
 xmpp4r (0.5)

Here is my config.ru file:

#!/usr/bin/env ruby
require 'thin'
require 'rack'

require ::File.expand_path('config/environment', File.dirname(__FILE__) )
run Myapp::Application

I've also tried using thin 1.3.1 with no luck. I've tried eventmachine-1.0.0.beta.2, but the Gemfile keeps wanting to use 0.12.10, even though I deleted Gemfile.lock before running bundle install.

I think the error regarding ActiveSupport::Dependencies means that I am using the wrong libraries somewhere, but I don't know how to figure out which libraries are incorrect.

Does anyone know what is causing this problem, or have a suggestion on how to debug it?


Solution

  • This link set me on the right path. After adding require 'active_support/dependencies', I next added require 'action_controller' to config.ru and I was able to access index.html through my URI. So my config.ru looks like

     #!/usr/bin/env ruby
     require 'thin'
     require 'rack'
     require 'active_support/dependencies'
     require 'action_controller'
    
     require ::File.expand_path('config/environment', File.dirname(__FILE__) )
     run Myapp::Application
    

    I have no idea why these requires are needed, but it seems to do the trick. The link says the reason is if you are using Rails 3 beta gems. Not sure if I am using such gems.