Topic: What to do about 500 errors and "Application Error - Rails app failed"

If you've ever moved your application from one computer to another for the first time or if you've just published your new app to some shared hosting provider you're almost sure to have seen this message at least once.

What to do when you see this message (or one like it):

Step One:

Set file permissions. Do it like so: ./public needs to be set to 755

chmod 755 public

./public/dispatch.fcgi (or dispatch.cgi - but don

Last edited by danger (2006-08-03 13:15:17)

Re: What to do about 500 errors and "Application Error - Rails app failed"

Ah, to have had this post the first time I tried moving a Rails app onto a live webserver!

Good post, danger.

Re: What to do about 500 errors and "Application Error - Rails app failed"

oh awesome! like adamp said, to have had this when I did my first textdrive install! excellent to have it all in one place for the future though - this one's definetly getting bookmarked!

great job!

Re: What to do about 500 errors and "Application Error - Rails app failed"

Thanks guys.  It took me the better part of a weekend to figure out my strugs with DreamHost the first time.  I remember googling around and thinking "Damn, we need documentation."  I REALLY hope nobody has to go through this 500 error anymore.

Re: What to do about 500 errors and "Application Error - Rails app failed"

Just want to add, sometimes I get this error if my database is not configured correctly so for posterity reasons you may also want to look into it.

Re: What to do about 500 errors and "Application Error - Rails app failed"

That's a good idea.  Dropping and re-adding the database and then running "rake migrate" is probably a really good step if the above don't work.

Re: What to do about 500 errors and "Application Error - Rails app failed"

Not sure how this is for everybody, but for my setup, I quite often have to "killall -9 dispatch.fcgi" (which will then cause the process to restart the next time you access the app) before noticing changes. smile

Re: What to do about 500 errors and "Application Error - Rails app failed"

I've had to do that a fair few times as well.  Though on many setups I find it works just as well to run "touch public/dispatch.fcgi" because the server will be forced to reload the files due to the new timestamp.

Re: What to do about 500 errors and "Application Error - Rails app failed"

We've had the error when we had an SQL query that took a realllllly long time.  App failed but query continued until finished!  This isn't good but I don't know how to stop the query from the failure point.

Re: What to do about 500 errors and "Application Error - Rails app failed"

Hmmm, that's an interesting problem.  I wonder how tough it would be for ActiveRecord to sense a timeout problem and raise (and log) that error rather than the dumb one.

Re: What to do about 500 errors and "Application Error - Rails app failed"

I need some help!  I'm having trouble getting rails working, I'm stuck with a Application error - Rails application failed to start properly"

I tried following Danger's steps here but when I get to chmod -R 0666 log it tells me:

chmod: `log': Permission denied

I have svn setup and deployed with capistrano.  I ran rake db:migrate and the dbs were successfully created.  I checked the permissions and the she-bang lines.  The Welcome to Rails page comes up, but anything else gives the Application Error.

I'm not seeing any logs being generated.  Capistrano makes a symlink log that points to a shared directory.  Is that what it's supposed to do?  No logs are appearing so I don't know what to troubleshoot.  I noticed that files in the script directory had rw -r -r permissions, seems like these should be executable right?

I tried running script/console production just to see if it worked and I get this:

/usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require': no such file to load -- readline (LoadError)
        from /usr/local/lib/ruby/1.8/irb/completion.rb:10
        from /usr/local/lib/ruby/1.8/irb/init.rb:252:in `load_modules'
        from /usr/local/lib/ruby/1.8/irb/init.rb:250:in `load_modules'
        from /usr/local/lib/ruby/1.8/irb/init.rb:21:in `setup'
        from /usr/local/lib/ruby/1.8/irb.rb:54:in `start'
        from /usr/local/bin/irb:13


Here are the some of the files involved, any help would be greatly appreciated!!!!!!!



deploy.rb

set :application, "rcl"
set :repository, "svn+ssh://myuser@64.128.80.102/home/myuser/svn/rcl/"
set :deploy_to, "/home/myuser/rcl/"
set :use_sudo, false
set :checkout, "export"
set :user, "myuser"

role :web, "www.reviewerjunction.com"
role :app, "www.reviewerjunction.com"
role :db,  "www.reviewerjunction.com", :primary => true

desc "Tasks to execute after code update"
    task :after_update_code, :roles => [:app, :db, :web] do
     # fix permissions
     run "chmod +x #{release_path}/script/process/reaper"
     run "chmod +x #{release_path}/script/process/spawner"
     run "chmod 755 #{release_path}/public/dispatch.*"
end
desc "Restarting after deployment"
    task :after_deploy, :roles => [:app, :db, :web] do
     run "touch /home/myuser/rcl/current/public/dispatch.fcgi"
end
desc "Restarting after rollback"
    task :after_rollback, :roles => [:app, :db, :web] do
     run "touch /home/myuser/rcl/current/public/dispatch.fcgi"
end

database.yml

development:
  adapter: mysql
  database: myuser_rclproduction
  username: myuser
  password: mypass
  host: localhost

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  database: myuser_rcltest
  username: myuser
  password: mypass
  host: localhost

production:
  adapter: mysql
  database: myuser_rclproduction
  username: myuser
  password: mypass
  host: localhost

environment.rb

ENV['RAILS_ENV'] ||= 'development'

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '1.1.6'

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence those specified here
 
  # Skip frameworks you're not going to use (only works if using vendor/rails)
  # config.frameworks -= [ :action_web_service, :action_mailer ]

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Force all environments to use the same logger level
  # (by default production uses :info, the others :debug)
  # config.log_level = :debug

  # Use the database for sessions instead of the file system
  # (create the session table with 'rake db:sessions:create')
  # config.action_controller.session_store = :active_record_store

  # Use SQL instead of Active Record's schema dumper when creating the test database.
  # This is necessary if your schema can't be completely dumped by the schema dumper,
  # like if you have constraints or database-specific column types
  # config.active_record.schema_format = :sql

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector

  # Make Active Record use UTC-base instead of local time
  # config.active_record.default_timezone = :utc
 
  # See Rails::Configuration for more options
end

# Add new inflection rules using the following format
# (all these examples are active by default):
# Inflector.inflections do |inflect|
#   inflect.plural /^(ox)$/i, '\1en'
#   inflect.singular /^(ox)en/i, '\1'
#   inflect.irregular 'person', 'people'
#   inflect.uncountable %w( fish sheep )
# end

# Include your application configuration below

dispatch.fcgi

#!/usr/local/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log
# and the GC period is nil (turned off).  A reasonable number of requests
# could range from 10-100 depending on the memory footprint of your app.
#
# Example:
#   # Default log path, normal GC behavior.
#   RailsFCGIHandler.process!
#
#   # Default log path, 50 requests between GC.
#   RailsFCGIHandler.process! nil, 50
#
#   # Custom log path, normal GC behavior.
#   RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log'
#
require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'

RailsFCGIHandler.process!

Re: What to do about 500 errors and "Application Error - Rails app failed"

My bad - that one line should have read:

$ chmod 766 log

Sorry!

Last edited by danger (2006-12-26 19:48:48)

Re: What to do about 500 errors and "Application Error - Rails app failed"

Thanks, I figured it was supposed to be 766.  I am unable to debug the application error because I don't have any log files.  Should those be created when an error occurs or do I need to generate them some other way?  I tried creating a file called development.log but it doesn't seem to be updating with any information.  Thanks!

Re: What to do about 500 errors and "Application Error - Rails app failed"

you can check whether log files can be generated by running the console:

$ ./script/console

then do some basic operation:

$ User.find(:all)

Then the mysql query along with some other info should be in ./log/development.log

Re: What to do about 500 errors and "Application Error - Rails app failed"

I'm not sure what I did this morning but suffice it to say, the coffee was still in the coffee cup....

I'm on Rails 1.2.1 and everything was fine yesterday. This morning I made a small change in one of my models to make a unit test pass. I also did something from the command line, trying to get the command right from memory to update a plugin, and I'm sure that's what changed it all. I closed that window before I realized I had any problems.

I've gone through everything in this post but I haven't found the problem yet. Or maybe the problem is in my development.log (below) but I'm not sure what to do about it. I think I've screwed up my configuration somehow. My automated tests all run and I can access my code through the console fine. I don't see any reference to my code in the log either.

[code: ruby]
marshal data too short

C:/ruby/lib/ruby/1.8/pstore.rb:354:in `load'

C:/ruby/lib/ruby/1.8/pstore.rb:354:in `load'

C:/ruby/lib/ruby/1.8/pstore.rb:307:in `transaction'

C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:71:in `initialize'

C:/ruby/lib/ruby/1.8/cgi/session.rb:273:in `initialize'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/cgi_process.rb:122:in `session'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/cgi_process.rb:154:in `stale_session_check!'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/cgi_process.rb:109:in `session'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:1052:in `assign_shortcuts_without_flash'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/flash.rb:140:in `assign_shortcuts'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:424:in `process_without_filters'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/filters.rb:624:in `process_without_session_management_support'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/session_management.rb:114:in `process'

C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.1/lib/action_controller/base.rb:330:in `process'

C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/dispatcher.rb:41:in `dispatch'

C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:113:in `handle_dispatch'

C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:79:in `service'

C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'

C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'

C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'

C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'

C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'

C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'

C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'

C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'

C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/webrick_server.rb:63:in `dispatch'

C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/servers/webrick.rb:59

C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require'

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in `new_constants_in'

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require'

C:/ruby/lib/ruby/gems/1.8/gems/rails-1.2.1/lib/commands/server.rb:39

C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require'

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:343:in `new_constants_in'

C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:496:in `require'

./script/server:3

-e:4
[/code]

Re: What to do about 500 errors and "Application Error - Rails app failed"

My source is in subversion so I just reverted to some earlier versions to prove to myself that it's configuration. I get the same error. I'm wondering if I should just reinstall Rails? I'm running locally on Windows XP. Is there an easy or recommended procedure, or anything to watch out for?

Re: What to do about 500 errors and "Application Error - Rails app failed"

Never mind, I fixed it by uninstalling Ruby, reinstalling, and going from there. It's been a frustrating 2 days (yesterday was something else).

Re: What to do about 500 errors and "Application Error - Rails app failed"

I'm also getting 'marshal data too short' but only when I log-in using 2 of my 27000 users. everything works fine for everyone else.

once I'm logged in under these two users. I can't navigate to any pages.

the backtrace from the log file is similar to the one above posted by dkov and it is related to PStore. I found other post on the internet about this problem but no solution.

my session are stored on disk as I did not change the rails default.

only turning closing the browser and reopening it solve the problem, so I can login again. then I can login with any other login, but if I use those 2 special login that we spot: it screw up my local session in some ways and makes any pages unbrowsable.

more than 10000 users succesfully login and had no problem.

Re: What to do about 500 errors and "Application Error - Rails app failed"

How are you storing the users in the session? Are you storing the entire model in the session or just the user id? If you are storing the entire model, this may be causing some problems.

Also, take a look at your users table. Do the records that are messing up look okay?

Railscasts - Free Ruby on Rails Screencasts

Re: What to do about 500 errors and "Application Error - Rails app failed"

I'm only storing the ID. I had problem before storing full AR objects, so I don't do it anymore. and definitely not for this project.

I've look at the user table and also the other related table around it. the rows look perfectly normal. I'm totally puzzled by this problem.