Skip to content

Commit 96c08b9

Browse files
committed
fix(ReconnectLDAPObject): Also reconnect on UNAVILABLE, CONNECT_ERROR and TIMEOUT
1 parent 36384c2 commit 96c08b9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/ldap/ldapobject.py

Lines changed: 7 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,10 @@ 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:: 3.5
837+
The exceptions :py:exc:`ldap.SERVER_DOWN`, :py:exc:`ldap.UNAVAILABLE`, :py:exc:`ldap.CONNECT_ERROR` and
838+
:py:exc:`ldap.TIMEOUT` (configurable via :py:attr:`_reconnect_exceptions`) now trigger a reconnect.
836839
"""
837840

838841
__transient_attrs__ = {
@@ -842,6 +845,7 @@ class ReconnectLDAPObject(SimpleLDAPObject):
842845
'_reconnect_lock',
843846
'_last_bind',
844847
}
848+
_reconnect_exceptions = (ldap.SERVER_DOWN, ldap.UNAVAILABLE, ldap.CONNECT_ERROR, ldap.TIMEOUT)
845849

846850
def __init__(
847851
self,uri,
@@ -970,7 +974,7 @@ def _apply_method_s(self,func,*args,**kwargs):
970974
self.reconnect(self._uri,retry_max=self._retry_max,retry_delay=self._retry_delay,force=False)
971975
try:
972976
return func(self,*args,**kwargs)
973-
except ldap.SERVER_DOWN:
977+
except self._reconnect_exceptions:
974978
# Try to reconnect
975979
self.reconnect(self._uri,retry_max=self._retry_max,retry_delay=self._retry_delay,force=True)
976980
# Re-try last operation

0 commit comments

Comments
 (0)