Skip to content

Commit b222122

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

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:: 4.0
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy