Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added additional error handling to the FastCGI dispatcher to catch ev…

…en errors taking down the entire process

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@969 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit c006bae4b8e0b44fccbd43e2982428aabdeb538e 1 parent 32e0138
David Heinemeier Hansson dhh authored
Showing with 20 additions and 12 deletions.
  1. +2 −0  railties/CHANGELOG
  2. +18 −12 railties/dispatches/dispatch.fcgi
2  railties/CHANGELOG
View
@@ -1,5 +1,7 @@
*SVN*
+* Added additional error handling to the FastCGI dispatcher to catch even errors taking down the entire process
+
* Improved the generated scaffold code a lot to take advantage of recent Rails developments #882 [Tobias Luetke]
* Combined the script/environment.rb used for gems and regular files version. If vendor/rails/* has all the frameworks, then files version is used, otherwise gems #878 [Nicholas Seckar]
30 railties/dispatches/dispatch.fcgi
View
@@ -1,20 +1,26 @@
#!/usr/local/bin/ruby
-require File.dirname(__FILE__) + "/../config/environment"
-require 'dispatcher'
-require 'fcgi'
+FASTCGI_CRASH_LOG_PATH = "#{RAILS_ROOT}/log/fastcgi.crash.log"
-log_file_path = "#{RAILS_ROOT}/log/fastcgi.crash.log"
+def dispatcher_error(e, msg = "")
+ error_message = "[#{Time.now}] Dispatcher failed to catch: #{e} (#{e.class})\n #{e.backtrace.join("\n ")}\n#{msg}"
+ Logger.new(FASTCGI_CRASH_LOG_PATH).fatal(error_message)
+rescue Object => log_error
+ STDERR << "Couldn't write to #{FASTCGI_CRASH_LOG_PATH} (#{e} [#{e.class}])\n" << error_message
+end
-FCGI.each_cgi do |cgi|
- begin
- Dispatcher.dispatch(cgi)
- rescue Object => e
- error_message = "[#{Time.now}] Dispatcher failed to catch: #{e} (#{e.class})\n #{e.backtrace.join("\n ")}\n"
+begin
+ require File.dirname(__FILE__) + "/../config/environment"
+ require 'dispatcher'
+ require 'fcgi'
+
+ FCGI.each_cgi do |cgi|
begin
- Logger.new(log_file_path).fatal(error_message)
- rescue Object => log_error
- STDERR << "Couldn't write to #{log_file_path} (#{log_error} [#{log_error.class}])\n" << error_message
+ Dispatcher.dispatch(cgi)
+ rescue Object => rails_error
+ dispatcher_error(rails_error)
end
end
+rescue Object => fcgi_error
+ dispatcher_error(fcgi_error, "FCGI process #{$$} killed by this error\n")
end
Please sign in to comment.
Something went wrong with that request. Please try again.