Bug 35852 - uldap.py Wrong reconnect count
uldap.py Wrong reconnect count
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: univention-lib
UCS 4.0
All Linux
: P5 normal (vote)
: UCS 4.0
Assigned To: Philipp Hahn
Felix Botner
: interim-2
Depends on: 34292 35841
Blocks: 35741
  Show dependency treegraph
 
Reported: 2014-09-09 20:14 CEST by Philipp Hahn
Modified: 2016-11-08 07:01 CET (History)
3 users (show)

See Also:
What kind of report is it?: ---
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Ticket number:
Bug group (optional):
Max CVSS v3 score:
hahn: Patch_Available+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Hahn univentionstaff 2014-09-09 20:14:16 CEST
+++ This bug was initially created as a clone of Bug #35741 +++

Bug #34292 (r48498) introduced the following bug:
126 class access:
128 »···def __init__(…
179 »···»···i=0
180 »···»···while i <= self.client_connection_attempt:
181 »···»···»···try:
182 »···»···»···»···self.__open(ca_certfile)
184 »···»···»···except ldap.SERVER_DOWN:
187 »···»···»···»···ud.debug(ud.LDAP, ud.INFO, "Can't contact LDAP server…
189 »···»···»···i+=1
...
204 »···def __open(self, ca_certfile):
211 »···»···self.lo = ldap.ldapobject.ReconnectLDAPObject(self.uri, trace_stack_limit=None, retry_max=self.client_connection_attempt, retry_delay=1)

This leads to the re-connect being performed n^2 times with UCS-4, as the code in python-ldap has been changed to re-connect also when calling start_tls_s():

06.09.14 12:11:52.770  LDAP        ( INFO    ) : Can't contact LDAP server. Try again (1/11)
...
06.09.14 12:12:01.791  LDAP        ( INFO    ) : Can't contact LDAP server. Try again (10/11)
...
Traceback (most recent call last):
  File "25reconnect_uldap", line 69, in <module>
    lo = _get_connection()
  File "25reconnect_uldap", line 34, in _get_connection
    return univention.uldap.getMachineConnection(ldap_master=False)
  File "/usr/lib/pymodules/python2.6/univention/uldap.py", line 113, in getMachineConnection
    raise ldap.SERVER_DOWN, e
ldap.SERVER_DOWN: {'desc': "Can't contact LDAP server"}
Comment 1 Philipp Hahn univentionstaff 2014-09-09 20:20:27 CEST
From 9c8f5aeec8092562f3d241555f5844d79400a54c Mon Sep 17 00:00:00 2001
Message-Id: <9c8f5aeec8092562f3d241555f5844d79400a54c.1410286807.git.hahn@univention.de>
From: Philipp Hahn <hahn@univention.de>
Date: Tue, 9 Sep 2014 20:16:32 +0200
Subject: [PATCH] Bug #35852 uldap: Fix LDAP reconnect count
Organization: Univention GmbH, Bremen, Germany

python-2.4.15 also re-connects internally for the start_tls_s() call,
which leads to the re-connect being done n^2 times now.

Remove the hand-rolled loop in favour of the python-ldap internal
handling, as calling ReconnectLDAPObject(retry_max=1) would disable the
re-tries for all other operations.

Also fix a string splitting error: "string" is deprecated and no longer
imported.
---
 .../ucs-4.0-0/base/univention-python/debian/changelog   |  6 ++++++
 .../ucs-4.0-0/base/univention-python/debian/control     |  2 +-
 .../ucs-4.0-0/base/univention-python/modules/uldap.py   | 17 ++---------------
 3 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/changelog b/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/changelog
index f9ae24f..b730b8b 100644
--- a/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/changelog
+++ b/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/changelog
@@ -1,3 +1,9 @@
+univention-python (8.0.1-1) unstable; urgency=low
+
+  * Bug #35852: Fix LDAP reconnect count
+
+ -- Philipp Hahn <hahn@univention.de>  Tue, 09 Sep 2014 20:13:58 +0200
+
 univention-python (8.0.0-3) unstable; urgency=low
 
   * Call explicit python_support (Bug #35138)
diff --git a/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/control b/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/control
index 9baee07..ddcbdfd 100644
--- a/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/control
+++ b/branches/ucs-4.0/ucs-4.0-0/base/univention-python/debian/control
@@ -10,7 +10,7 @@ XS-Python-Version: 2.6,2.7
 Package: python-univention
 Architecture: all
 Depends: ${misc:Depends}, ${python:Depends},
- python-ldap,
+ python-ldap (>= 2.4.15),
  python-dns,
  python-univention-debug,
  python-cracklib
diff --git a/branches/ucs-4.0/ucs-4.0-0/base/univention-python/modules/uldap.py b/branches/ucs-4.0/ucs-4.0-0/base/univention-python/modules/uldap.py
index 8933177..a1c52c9 100644
--- a/branches/ucs-4.0/ucs-4.0-0/base/univention-python/modules/uldap.py
+++ b/branches/ucs-4.0/ucs-4.0-0/base/univention-python/modules/uldap.py
@@ -31,9 +31,6 @@
 # <http://www.gnu.org/licenses/>.
 
 import ldap
-import types
-import time
-import sys
 import ldap.schema
 import univention.debug
 from univention.config_registry import ConfigRegistry
@@ -84,7 +81,7 @@ def getBackupConnection(start_tls=2, decode_ignorelist=[]):
                lo=access(host=ucr['ldap/master'], port=port, base=ucr['ldap/base'], binddn='cn=backup,'+ucr['ldap/base'], bindpw=bindpw, start_tls=start_tls, decode_ignorelist=decode_ignorelist)
        except ldap.SERVER_DOWN, e:
                if ucr['ldap/backup']:
-                       backup=string.split(ucr['ldap/backup'],' ')[0]
+                       backup=ucr['ldap/backup'].split(' ')[0]
                        lo=access(host=backup, port=port, base=ucr['ldap/base'], binddn='cn=backup,'+ucr['ldap/base'], bindpw=bindpw, start_tls=start_tls, decode_ignorelist=decode_ignorelist)
                else:
                        raise ldap.SERVER_DOWN, e
@@ -176,17 +173,7 @@ class access:
 
                self.client_connection_attempt = client_retry_count+1
 
-               i=0
-               while i <= self.client_connection_attempt:
-                       try:
-                               self.__open(ca_certfile)
-                               break
-                       except ldap.SERVER_DOWN:
-                               if i >= (self.client_connection_attempt-1):
-                                       raise
-                               univention.debug.debug(univention.debug.LDAP, univention.debug.INFO, "Can't contact LDAP server. Try again (%d/%d)" % (i+1,self.client_connection_attempt))
-                               time.sleep(1)
-                       i+=1
+               self.__open(ca_certfile)
 
        def __encode_pwd(self, pwd):
                if isinstance( pwd, unicode ):
-- 
1.9.1
Comment 2 Philipp Hahn univentionstaff 2014-09-10 09:35:03 CEST
r53508 | Bug #35852 uldap: Fix LDAP reconnect count
 patch committed

Package: univention-python
Version: 8.0.1-1.143.201409100916
Branch: ucs_4.0-0

r53513 | Bug #35741 uldap: retry changelog
+                 The new version of the package <package>python-ldap</package> caused the <classname>univention.uld
ap</classname> implementation to retry failed connects too many times.
+                 This has been fixed (<ulink url="&ucsbug;35841">Bug 35841</ulink>, <ulink url="&ucsbug;35741">Bug 
35741</ulink>).

<http://jenkins.knut.univention.de:8080/job/UCS-4.0/job/UCS-4.0-0/job/Release%20Notes/18/artifact/webroot/release-notes-4.0-0-en.html#changelog:lib>
Comment 3 Felix Botner univentionstaff 2014-10-02 15:28:07 CEST
FAIL - Changelog?

OK -

/etc/init.d/slapd stop
python
import univention.uldap
univention.uldap.getAdminConnection()

Trying 1. (of 11) reconnect to ldap://master.new.intranet:7389...
...
Trying 11. (of 11) reconnect to ldap://master.new.intranet:7389...
=> LDAPError - SERVER_DOWN: {'desc': "Can't contact LDAP server"}
Comment 4 Philipp Hahn univentionstaff 2014-10-02 15:53:27 CEST
(In reply to Felix Botner from comment #3)
> FAIL - Changelog?

r54160 | Bug #35852 uldap: Fix bug number
 35741 (ucs-test) → 35852 (univention-python)
Comment 5 Felix Botner univentionstaff 2014-10-02 16:12:49 CEST
OK
Comment 6 Stefan Gohmann univentionstaff 2014-11-26 06:55:04 CET
UCS 4.0-0 has been released:
 http://docs.univention.de/release-notes-4.0-0-en.html
 http://docs.univention.de/release-notes-4.0-0-de.html

If this error occurs again, please use "Clone This Bug".