ReconnectLDAPObject doesn't reconnect after main failure

Alain Spineux aspineux at gmail.com
Sat Jan 27 01:57:49 CET 2007


Yes I got it !

The problem is the failed statement has initiated a new connection
(when the server is down)
calling initialize (that doesn't fail) and bind that fail but is in a
try: except:  block in ReconnectLDAPObject.reconnect() !
Then the server restart and the next statement get advantages of the
work done initialize


# first stop the service
ldap_service('stop')
# initiate a connection
l=ldap.initialize(ldap_url.initializeUrl()) # I dont use ReconnectLDAPObject !
try:
    l.simple_bind_s(ldap_url.who, ldap_url.cred)
except ldap.SERVER_DOWN:
    pass # bind fail like in ReconnectLDAPObject.reconnect()
ldap_service('start')
check_connection() # that return an empty string


The probleme is initialize don't initialize any connection !
from  "man 3 ldap" :

       The  basic  interaction  is  as  follows.  A session handle is created
       using ldap_initialize(3) and set the protocol version to 3 by  calling
       ldap_set_option(3).  The underlying session is established first oper-
       ation is issued.  This would generally be a Start TLS or  Bind  opera-
       tion.

The problem is that the first operation after Initialize will never
put the connection into failing
state when server is down!
The problem is probably into libldap into the "auto connect at first
operation" like
described into man 3 ldap

This let us do something like

l=ldap.initialize(ldap_url.initializeUrl()) # I dont use ReconnectLDAPObject !

while True:
    try:
        l.simple_bind_s(ldap_url.who, ldap_url.cred)
    except ldap.SERVER_DOWN:
        time.sleep(1)
    else:
        break
print 'Connected'

I don't know if this is a feature or a bug into libldap !

Then the logic of my patch look to be the good one. I still need to
verify it once more.

I go to sleep now


On 1/26/07, Michael Ströder <michael at stroeder.com> wrote:
> Alain Spineux wrote:
> > When testing ReconnectLDAPObject I found a bug.
> > The object doesn't reconnect after a main failure !
> > [..]
> > I thing the main probleme is here !
> > Look !
>
> Yes, I can reproduce your observation. Thanks for pointing it out.
>
> > l=ldap.ldapobject.ReconnectLDAPObject(ldap_url.initializeUrl())
> > print 'search', l.search_s(ldap_url.dn, ldap.SCOPE_SUBTREE, "(objectClass=*)")
> >
> > this work too ! And don't give any error while their is no bind !
> > work like if l.simple_bind_s('', '') where used just before the search !
>
> Yes, this works as intended in LDAPv3. In opposite to LDAPv2 you MAY
> send a LDAP request without prior bind request.
>
> > I wrote a patch but this is only a workaround that detect the main
> > failure, set a flag and force a reconnect before any request if the
> > flag is set.
>
> Where's the patch? Can't figure out why it does not send the formerly
> sent bind request. It has all the data around. And if you take the
> server down it will re-send the bind request.
>
> Ciao, Michael.
>


-- 
--
Alain Spineux
aspineux gmail com
May the sources be with you



More information about the python-ldap mailing list