Skip to content

Commit 48edd06

Browse files
committed
Fix reconnecting in certain cases by adding ldap.UNAVILABLE
1 parent 5c32122 commit 48edd06

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Lib/ldap/ldapobject.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,7 @@ def get_naming_contexts(self):
820820
class ReconnectLDAPObject(SimpleLDAPObject):
821821
"""
822822
:py:class:`SimpleLDAPObject` subclass whose synchronous request methods
823-
automatically reconnect and re-try in case of server failure
824-
(:exc:`ldap.SERVER_DOWN`).
823+
automatically reconnect and re-try in case of server failure.
825824
826825
The first arguments are same as for the :py:func:`~ldap.initialize()`
827826
function.
@@ -833,6 +832,11 @@ class ReconnectLDAPObject(SimpleLDAPObject):
833832
* retry_delay: specifies the time in seconds between reconnect attempts.
834833
835834
This class also implements the pickle protocol.
835+
836+
.. versionadded:: 4.0
837+
The exceptions which cause a re-connection are now configurable via :py:attr:`_reconnect_exceptions`.
838+
The exceptions :py:exc:`ldap.UNAVAILABLE`, :py:exc:`ldap.CONNECT_ERROR` and
839+
:py:exc:`ldap.TIMEOUT` now also trigger a reconnect.
836840
"""
837841

838842
__transient_attrs__ = {
@@ -842,6 +846,7 @@ class ReconnectLDAPObject(SimpleLDAPObject):
842846
'_reconnect_lock',
843847
'_last_bind',
844848
}
849+
_reconnect_exceptions = (ldap.SERVER_DOWN, ldap.UNAVAILABLE, ldap.CONNECT_ERROR, ldap.TIMEOUT)
845850

846851
def __init__(
847852
self,uri,
@@ -970,7 +975,7 @@ def _apply_method_s(self,func,*args,**kwargs):
970975
self.reconnect(self._uri,retry_max=self._retry_max,retry_delay=self._retry_delay,force=False)
971976
try:
972977
return func(self,*args,**kwargs)
973-
except ldap.SERVER_DOWN:
978+
except self._reconnect_exceptions:
974979
# Try to reconnect
975980
self.reconnect(self._uri,retry_max=self._retry_max,retry_delay=self._retry_delay,force=True)
976981
# Re-try last operation

0 commit comments

Comments
 (0)