我有一个非常奇怪的错误,我需要一些线索。考虑一下:
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堆栈的其他部分吗?
答案 0 :(得分:0)
错误是未定义的方法logged_in?在你的IpnSubscriptionNotificationsController中,这个控制器继承自ApplicationController,你肯定在ApplicationController中包含AuthenticatedSystem模块,可能你可以先试试这个
答案 1 :(得分:0)
可能这不能解决您的问题,但您应该使用around_filter:set_timezone而不是过滤器之前。看看这个:http://www.elabs.se/blog/36-working-with-time-zones-in-ruby-on-rails#working_with_multiple_user_time_zones