rails(5.0.0.1)
红宝石(2.3.1)
我们正在遇到一些LDAP错误(非常偶然)基础设施服务器(我们没有维护)正在关闭先前Errno :: ECONNRESET错误的连接。
我试图通过重试来捕获current_user的错误,但是遇到了一些有趣的场景。第一次调用" current_user.try(:username)"抛出预期的ldap错误(重现我给它一个应该总是失败的坏服务器地址)。点击重试后第二次调用" current_user.try(:username)"不会抛出错误,但current_user仍为零。为丑陋的调试代码道歉
def do_current_user
count = 0
begin
logger.error "Try in do_current_user #{count}"
if current_user.nil?
logger.error "Current_user is nill at count #{count}"
end
current_user.try(:username)
rescue Errno::ECONNRESET, Net::LDAP::Error => e
count = count + 1
logger.error "Exception hit with authenticate \n#{e.backtrace.join("\n\t")}\n Retrying the request"
retry if count < 3
end
end
不确定是否有其他人对此提示有任何提示。在devise / controllers / helpers.rb中,助手没有太多帮助;可能只有一个,但从初始看起来似乎是在ldap模块中更深层次的缓存:
def current_#{mapping}
@current_#{mapping} ||= warden.authenticate(scope: :#{mapping})
end