13

I originally posted a question relating to this problem on serverfault.com: https://serverfault.com/questions/152587/apache-mod-proxy-to-another-server

I have since realized that this is not an issue with my server setup, but my rails application. I have set this application up server-wise the exact same as another functioning rails app I have running on the same server. When I start the server my mongrel.log looks like this:

** Daemonized, any open files are closed.  Look at /var/www/osuwebdev/tmp/pids/mongrel.pid and log/mongrel.log for info.
** Starting Mongrel listening at 0.0.0.0:8080
** Starting Rails with production environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.5 available at 0.0.0.0:8080
** Writing PID file to /var/www/osuwebdev/tmp/pids/mongrel.pid

When I load a page this pops up in the log:

Wed Jun 30 19:46:10 +0000 2010: Error calling Dispatcher.dispatch #<NoMethodError: undefined method `[]' for nil:NilClass>
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/cgi.rb:108:in `send_cookies'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/cgi.rb:136:in `out'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/http_response.rb:65:in `start'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/cgi.rb:135:in `out'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:81:in `process'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:159:in `process_client'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:158:in `each'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:158:in `process_client'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `initialize'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `new'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:285:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `initialize'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `new'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel.rb:268:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:282:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:281:in `each'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/configurator.rb:281:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/command.rb:212:in `run'
/var/lib/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
/usr/local/bin/mongrel_rails:19:in `load'
/usr/local/bin/mongrel_rails:19

I cannot figure out what is different about this app that may cause this issue.

Community
  • 1
  • 1
trobrock
  • 46,549
  • 11
  • 40
  • 46
  • found this old ticket http://dev.rubyonrails.org/ticket/6716 similar error. Do you have any include statements outside of your classes? Also did you check your class names, to make sure that you aren't inadvertantly monkey-patching a class? – Geoff Lanotte Jun 30 '10 at 22:13
  • I do have a "Resources" model and controller, could that be causing it? I don't believe I am using any include statements. – trobrock Jun 30 '10 at 23:16
  • I commented out all relevant code to the "Resource" model and it didnt have any effect, I also do not see any includes in my code. – trobrock Jun 30 '10 at 23:25
  • 2
    I did find this https://rails.lighthouseapp.com/projects/8994/tickets/4690 which looks very similar, and gets close to a fix with the code at the end of that post, but still doesnt work correctly. I don't know what is different about this app that is causing this. (EDIT: just realized this is my only 2.3.8 app all others are 2.3.5) – trobrock Jun 30 '10 at 23:40
  • 1
    I downgraded the app to 2.3.5 and all works well – trobrock Jul 02 '10 at 02:05
  • I once had a model named Response and all hell broke loose in RSpec... – awendt May 23 '11 at 15:22
  • The downgrade worked... but you probably don't feel great if that means you are stuck on that. It's starting to get old (was released in 2009). You may want to try going to rails 2.3.11 It should be relatively painless. Rails3 is a much bigger deal though (considerably more work). – Michael Durrant Sep 25 '11 at 21:00

3 Answers3

3

I believe this is a weird combination of bugs in Rack, Mongrel, and Rails.

  1. Save this ruby code in your app to config/mongrel.rb: http://gist.github.com/471663

  2. In your config/environment.rb, at the very end of the file add: require File.join(File.dirname(File.expand_path(FILE)), 'mongrel')

  3. In that same file add this line in the Rails::initializer.run block: config.gem "mongrel"

Longer explanation of the problem here: https://rails.lighthouseapp.com/projects/8994/tickets/4690-mongrel-doesnt-work-with-rails-238

This has definitely worked for a Rails 2.3.8 app, though I patched it slightly differently than described above.

rkb
  • 3,442
  • 19
  • 25
  • I experienced the same problem in an app using Rails 2.3.11 some time around June 2011 and successfully applied a similar workaround. According to my code, I got the patch from https://gist.github.com/826692. – Rich Drummond Aug 08 '12 at 05:01
  • @rkb Thank you very much! We experienced the exactly same problem in June, 2016 on Rails 2.3.18. This workaround is still valid, except that we have to change `2.3.8` with `2.3.18` on `config/mongrel.rb` and add `require File.join(File.dirname(File.expand_path(__FILE__)), 'mongrel')` to the `config/environment.rb`. Note that two underscores around `FILE` are required. – Tsutomu Jun 29 '16 at 07:07
0

Do you still see the problem on subsequent GET requests? I had a similar problem where my Rails app would run fine under WEBrick but not under Mongrel but found somewhere on the internets (here's a link that shows a similar version of the problem) that older versions of Mongrel mishandle the first request to the page but handle subsequent requests ok.

The workaround we put in was that whenever we started the app, we'd have curl perform a GET on the app to 'prime' Mongrel.

Chris Bunch
  • 87,773
  • 37
  • 126
  • 127
0

This is usually a fail reading a yaml file for config. It has set up a config object to get values from and the entry in the yaml file for your environment isn't there so the object is nil.

Are you running any gems that have a yaml file that maybe isn't set up for development?

I don't know why going back to 2.3.5 would help - it might be that it loads things in a different order and the config information is available.

Ghoti
  • 2,388
  • 1
  • 18
  • 22