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:
parent
7734b7f45d
commit
a74cf70ff4
|
@ -250,6 +250,8 @@ class ConnectionManager(object):
|
||||||
# trying retry_max times in a row with a fresh connector
|
# trying retry_max times in a row with a fresh connector
|
||||||
while tries < self.retry_max and not connected:
|
while tries < self.retry_max and not connected:
|
||||||
try:
|
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,
|
conn = self.connector_cls(self.uri, retry_max=self.retry_max,
|
||||||
retry_delay=self.retry_delay)
|
retry_delay=self.retry_delay)
|
||||||
conn.timeout = self.timeout
|
conn.timeout = self.timeout
|
||||||
|
@ -262,15 +264,15 @@ class ConnectionManager(object):
|
||||||
break
|
break
|
||||||
except ldap.LDAPError as error:
|
except ldap.LDAPError as error:
|
||||||
exc = error
|
exc = error
|
||||||
time.sleep(self.retry_delay)
|
tries += 1
|
||||||
if tries < self.retry_max:
|
if tries < self.retry_max:
|
||||||
log.info('Failure attempting to create and bind '
|
log.info('Failure attempting to create and bind '
|
||||||
'connector; will retry after %r seconds',
|
'connector; will retry after %r seconds',
|
||||||
self.retry_delay, exc_info=True)
|
self.retry_delay, exc_info=True)
|
||||||
|
time.sleep(self.retry_delay)
|
||||||
else:
|
else:
|
||||||
log.error('Failure attempting to create and bind '
|
log.error('Failure attempting to create and bind '
|
||||||
'connector', exc_info=True)
|
'connector', exc_info=True)
|
||||||
tries += 1
|
|
||||||
|
|
||||||
if not connected:
|
if not connected:
|
||||||
if isinstance(exc, (ldap.NO_SUCH_OBJECT,
|
if isinstance(exc, (ldap.NO_SUCH_OBJECT,
|
||||||
|
|
Loading…
Reference in New Issue