Commit c3436bd556bd0fe3811e7a7a687ed98959c31722:
    Implement a simple-minded single retry


Branch: refs/heads/master
Author: Sebb <[email protected]>
Committer: Sebb <[email protected]>
Pusher: sebb <[email protected]>

------------------------------------------------------------
lib/whimsy/asf/ldap.rb                                       | +++++++ ---
------------------------------------------------------------
19 changes: 14 additions, 5 deletions.
------------------------------------------------------------


diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index c9309ec..0376c64 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -122,8 +122,6 @@ def self.ldap
 
   # search with a scope of one
   def self.search_one(base, filter, attrs=nil)
-    init_ldap unless defined? @ldap
-    return [] unless @ldap
 
     target = @ldap.get_option(::LDAP::LDAP_OPT_HOST_NAME) rescue '?'
     cmd = "ldapsearch -x -LLL -b #{base} -s one #{filter} " +
@@ -131,12 +129,23 @@ def self.search_one(base, filter, attrs=nil)
 
     Wunderbar.info "[#{target}] #{cmd}"
 
+    # simple-minded single retry
     begin
-      result = @ldap.search2(base, ::LDAP::LDAP_SCOPE_ONELEVEL, filter, attrs)
+      _search_one(base, filter, attrs)
     rescue Exception => re
-      Wunderbar.warn "[#{target}] => #{re.inspect} for #{cmd}"
-      raise
+      Wunderbar.warn "[#{target}] => #{re.inspect} for #{cmd}, retrying ..."
+      @ldap.unbind rescue nil
+      @ldap = false # force new connection
+      # Let this one fail 
+      _search_one(base, filter, attrs)
     end
+  end
+
+  def self._search_one(base, filter, attrs)
+    init_ldap unless @ldap
+    return [] unless @ldap
+
+    result = @ldap.search2(base, ::LDAP::LDAP_SCOPE_ONELEVEL, filter, attrs)
 
     result.map! {|hash| hash[attrs]} if String === attrs
 

Reply via email to