Weird problem with Rails app and Mongrel
Asked Answered
C

3

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.

Catheryncatheter answered 30/6, 2010 at 19:53 Comment(7)
found this old ticket 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?Lupelupee
I do have a "Resources" model and controller, could that be causing it? I don't believe I am using any include statements.Catheryncatheter
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.Catheryncatheter
I did find this 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)Catheryncatheter
I downgraded the app to 2.3.5 and all works wellCatheryncatheter
I once had a model named Response and all hell broke loose in RSpec...Mutualism
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).Tieck
W
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.

Wilser answered 17/12, 2011 at 9:9 Comment(2)
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 gist.github.com/826692.Bobbobb
@Wilser 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.Synchronize
E
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.

Eal answered 30/6, 2010 at 23:45 Comment(0)
H
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.

Hillis answered 25/5, 2011 at 10:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.