Skip to content

Commit

Permalink
Retry if bind cannot contact server
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Oct 4, 2024
1 parent 5842336 commit f12e856
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/whimsy/asf/ldap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,30 @@ def self.bind(user=nil, password=nil, &block)
end

dn = ASF::Person.new(user).dn
raise ::LDAP::ResultError.new('Unknown user') unless dn

begin
@ldap.unbind if @ldap&.bound?
rescue StandardError
# ignore
end
ldap = ASF._init_ldap(true, self.rwhosts)
if block
ASF.flush_weakrefs
ldap.bind(dn, password, &block)
ASF._init_ldap(true)
else
ldap.bind(dn, password)
self.rwhosts.each do |rwhost|
begin
ldap = ASF._init_ldap(true, [rwhost])
if block
ASF.flush_weakrefs
ldap.bind(dn, password, &block)
ASF._init_ldap(true)
else
ldap.bind(dn, password)
end
break
rescue ::LDAP::ResultError => e
if e.message == "Can't contact LDAP server" # Any others worth a retry?
Wunderbar.warn "#{rwhost}: #{e.inspect}, continuing"
else
raise
end
end
end
ensure
ASF.flush_weakrefs
Expand Down

0 comments on commit f12e856

Please sign in to comment.