Leaving a connection open

Ron Teitelbaum Ron at USMedRec.com
Fri Mar 28 00:49:14 CET 2008

> From: Michael Ströder
> Ron Teitelbaum wrote:
> > I have a few questions about leaving a bound connection open for sharing
> > (python 2.4.4, python-ldap 2.2.1 - openldap 2.3-2.3.30 on Ubuntu 7.04).
> >
> > I'm using Async messages is there any benefit to using
> ReconnectLdapObject?
> No. If you're solely using the async methods you have to implement your
> own
> try-except block catching ldap.SERVER_DOWN and re-initiate whatever LDAP
> operation(s) seems appropriate in your application.

Ok I'll switch it back out.  Thanks.
> Please elaborate on why you're using the async methods. There are only
> rare
> cases where this really makes sense (e.g. bulk data processing with
> ldap.async or resiter, high-performance proxying with many outstanding
> search requests). If you have a threaded application you might want to
> think
> about using several pooled connections.

I'm calling out from smalltalk to python and our vm is hung whenever we are
waiting on python.  The async methods were just what we needed to allow
processing.  We are handling a large number of connections and multiple
threads and we are doing some pretty intensive processing on the app so
having the vm die for a call out is not an option. 

> > I noticed that the comments
> > http://vmspython.dyndns.org/pyhtmldoc/ldap.ldapobject.html said that the
> > class was intended for synchronous calls.
> Yupp. How else should it catch the ldap.SERVER_DOWN exception and do the
> re-connect without the application noticing it?

Yeah, I'm starting to understand that.  I'm getting
can't-contact-ldap-server errors that I thought this would help with.  Note,
I believe this is different from the server down error you are mentioning.  

How can I create the server_down error for testing?  Would shutting off
slapd cause this error (I assume), or would that cause other problems in
python-ldap, is there an easier way?

> > Is it ok to leave the connection open for long periods like a month?  Is
> it
> > realistic to believe that the connection would remain stable and be
> useable
> > for production if left open?
> This also depends on your server's configuration. There are server
> configuration directives to shorten the life-time of LDAP connections. I'd
> recommend to always implement an appropriate re-connect functionality
> within
> your application.
> > Is there a way to tell if the connection died so that I can reconnect a
> > shared connection if the connection dropped off?
> I'd recommend to send the operation and re-connect and re-send the
> operation
> if needed. Testing the connecting with a LDAP request will also result in
> a
> ldap.SERVER_DOWN exception to be raised and it's an extra LDAP request
> sent
> => extra roundtrip time.
> > I tried unbind and whoami_s but got a very nasty memory error after a
> > very long delay.
> Note that this shouldn't happen in python-ldap 2.3.1+ built from source
> against OpenLDAP 2.3 libs straigt built with OpenSSL (not gnu-tls). But
> please report memory errors providing more details. We're tracking down
> some
> issues in recent CVS but not sure if you're hitting these bugs.

We are assessing our production environment.  For now we are staying with
Python2.4.4, is python-ldap 2.3.1 stable with Python-2.4.4?

> Please also note that always unbind_s() should be called. 

I thought unbind and unbind_s called the same method internally.  Do I need
to change my calls to unbind_s?  Is that for clarity or is there an
implementation difference?

> The unbind call
> is
> synchronous by nature and closes the connection. Calling whoami_s() only
> make sense if the LDAP server supports this particular extended operation.
> Not many LDAP server do this though.

Thank you very much for your help,


More information about the python-ldap mailing list