Browse Source

Improve connection retry logging

The logging around the connection retry logic logs an info level
message when it fails to connect to the server, but still has retry
attempts left.  Due to the way we increment the counter for the
number of connection attempts, we log this same message when the
final attempt has failed.  There is an error level log message in
the code that is never reached due to this.

This patch changes the location where we increment the connection
attempt counter, which results in the proper error message being
logged when we fail on the final attempt.  The retry wait is also
moved to be after the info level message, as it states that it is
about to wait before retrying.  The current logic of waiting before
logging the message doesn't actually match what the message says.
I also added a debug level log message that indicates what connection
attempt it is about to make to help troubleshoot the retry logic.

Change-Id: Ib05d510b8816b5e0670b92749412378a100667d0
Nathan Kinder 5 months ago
parent
commit
a74cf70ff4
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      ldappool/__init__.py

+ 4
- 2
ldappool/__init__.py View File

@@ -250,6 +250,8 @@ class ConnectionManager(object):
250 250
         # trying retry_max times in a row with a fresh connector
251 251
         while tries < self.retry_max and not connected:
252 252
             try:
253
+                log.debug('Attempting to create a new connector '
254
+                          'to %s (attempt %d)', self.uri, tries + 1)
253 255
                 conn = self.connector_cls(self.uri, retry_max=self.retry_max,
254 256
                                           retry_delay=self.retry_delay)
255 257
                 conn.timeout = self.timeout
@@ -262,15 +264,15 @@ class ConnectionManager(object):
262 264
                 break
263 265
             except ldap.LDAPError as error:
264 266
                 exc = error
265
-                time.sleep(self.retry_delay)
267
+                tries += 1
266 268
                 if tries < self.retry_max:
267 269
                     log.info('Failure attempting to create and bind '
268 270
                              'connector; will retry after %r seconds',
269 271
                              self.retry_delay, exc_info=True)
272
+                    time.sleep(self.retry_delay)
270 273
                 else:
271 274
                     log.error('Failure attempting to create and bind '
272 275
                               'connector', exc_info=True)
273
-                tries += 1
274 276
 
275 277
         if not connected:
276 278
             if isinstance(exc, (ldap.NO_SUCH_OBJECT,

Loading…
Cancel
Save