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
This commit is contained in:
Nathan Kinder 2018-10-30 19:09:39 -07:00
parent 7734b7f45d
commit a74cf70ff4
1 changed files with 4 additions and 2 deletions

View File

@ -250,6 +250,8 @@ class ConnectionManager(object):
# trying retry_max times in a row with a fresh connector
while tries < self.retry_max and not connected:
try:
log.debug('Attempting to create a new connector '
'to %s (attempt %d)', self.uri, tries + 1)
conn = self.connector_cls(self.uri, retry_max=self.retry_max,
retry_delay=self.retry_delay)
conn.timeout = self.timeout
@ -262,15 +264,15 @@ class ConnectionManager(object):
break
except ldap.LDAPError as error:
exc = error
time.sleep(self.retry_delay)
tries += 1
if tries < self.retry_max:
log.info('Failure attempting to create and bind '
'connector; will retry after %r seconds',
self.retry_delay, exc_info=True)
time.sleep(self.retry_delay)
else:
log.error('Failure attempting to create and bind '
'connector', exc_info=True)
tries += 1
if not connected:
if isinstance(exc, (ldap.NO_SUCH_OBJECT,