From a74cf70ff4ab2d99e63a4050f08a01ddbaf5bf79 Mon Sep 17 00:00:00 2001 From: Nathan Kinder Date: Tue, 30 Oct 2018 19:09:39 -0700 Subject: [PATCH] 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 --- ldappool/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ldappool/__init__.py b/ldappool/__init__.py index bf7c1be..0428ff1 100644 --- a/ldappool/__init__.py +++ b/ldappool/__init__.py @@ -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,