Silent ruby / rails crash causes it to consume all memory and crash the server
I have a very strange error that I need to be aware of. Consider this:
class ApplicationController < ActionController::Base
before_filter :set_timezone
def set_timezone
if logged_in?
Time.zone = current_user.time_zone
end
end
When PayPal tries to send a notification, it comes up like this:
Started POST "/ipn_subscription_notifications" for 173.0.82.126 at 2012-03-15 04:11:45 -0400
Processing by IpnSubscriptionNotificationsController#create as HTML
Parameters: {"txn_type"=>"subscr_signup", etc...
And here he was hanged. Ruby starts chewing on memory until the machine crashes. This is the fix:
def set_timezone
if current_user
Time.zone = current_user.time_zone
end
end
Let's look at logged_in?
:
module AuthenticatedSystem
def logged_in?
current_user ? true : false
end
Which is logically equivalent to a fix.
I suspect the error is being thrown and broken and someone is restarting the request process. AuthenticatedSystem
is definitely suspected.
This doesn't happen in the development environment, it throws an error and returns 500:
Started POST "/ipn_subscription_notifications" for 127.0.0.1 at 2012-03-15 15:19:39 -0700
Processing by IpnSubscriptionNotificationsController#create as */*
Parameters: {"foobar"=>nil}
Completed 500 Internal Server Error in 9ms
NoMethodError (undefined method `logged_in?' for #<IpnSubscriptionNotificationsController:0xdfdaaf4>):
app/controllers/application_controller.rb:8:in `set_timezone'
Rendered /usr/local/rvm/gems/ruby-1.9.2-p180@ce2/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-p180@ce2/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered /usr/local/rvm/gems/ruby-1.9.2-p180@ce2/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4.8ms)
[2012-03-15 15:19:40] ERROR Errno::ECONNRESET: Connection reset by peer
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
/usr/local/rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
Detecting such failures and handling them gracefully is my goal.
Any ideas? Can I use Passenger or some other part of the Rails stack?
source to share
This may not solve your problem, but you should use round_filter: set_timezone instead of filter. Take a look at this: http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails#working_with_multiple_user_time_zones
source to share