无提示的ruby/rails故障会导致它消耗所有内存并使服务器崩溃



我有一个非常奇怪的错误,我需要一些线索

class ApplicationController < ActionController::Base
  before_filter :set_timezone
  def set_timezone
    if logged_in?
      Time.zone = current_user.time_zone
    end
  end

当PayPal试图发送通知时,它会像这样出现:

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...

在这里它被挂断了。Ruby开始占用内存,直到机器崩溃。这是修复:

def set_timezone
  if current_user
    Time.zone = current_user.time_zone
  end
end

让我们看看logged_in?:

module AuthenticatedSystem
  def logged_in?
    current_user ? true : false
  end

这在逻辑上等同于修复。

我怀疑有人抛出并捕获了一个错误,并且有人正在重新启动请求过程。AuthenticatedSystem无疑是可疑的。

这在开发环境中不会发生,它抛出一个错误并返回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'

我的目标是发现并优雅地处理这些故障。

有什么想法吗?我可以给Passenger或Rails堆栈的其他部分安装仪器吗?

错误是未定义的方法logged_in?在您的IpSubscriptionNotificationsController中,并且此控制器继承自ApplicationController,您确定在ApplicationController中包含AuthenticatedSystem模块吗?您可以尝试第一个

这可能不能解决您的问题,但您应该使用around_filter:set_timezone,而不是在filter之前。看看这个:http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails#working_with_multiple_user_time_zones

最新更新