From c006bae4b8e0b44fccbd43e2982428aabdeb538e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 21 Mar 2005 17:46:31 +0000 Subject: Added additional error handling to the FastCGI dispatcher to catch even errors taking down the entire process git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@969 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 2 ++ railties/dispatches/dispatch.fcgi | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/railties/CHANGELOG b/railties/CHANGELOG index c8c0fa540a..ce3eabcec6 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -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] diff --git a/railties/dispatches/dispatch.fcgi b/railties/dispatches/dispatch.fcgi index 1c88d902df..ffe5b57812 100755 --- a/railties/dispatches/dispatch.fcgi +++ b/railties/dispatches/dispatch.fcgi @@ -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 \ No newline at end of file -- cgit v1.2.3