Leaving a connection open

Michael Ströder michael at stroeder.com
Thu Mar 27 23:32:46 CET 2008


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.

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 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?

> 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.

Please also note that always unbind_s() should be called. 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.

Ciao, Michael.




More information about the python-ldap mailing list