Monday, February 9, 2015

Contrary to what I considered possible, LDAP server

somehow notifies connected clients when being shut down.
So when you have an open connection to said server, you don't receive ldap.TIMEOUT exception as I expected. You get ldap.SERVER_DOWN.

Something to watch out for when you're working with LDAP.
Like so:
try:
    data = conn.search_s(base_dn, scope, search_filter, retrieve_attributes)
    log.debug("Searched for attribute(s) of LDAP base DN {0}, filter {1}".format(base_dn, search_filter))
    return data
except (ldap.TIMEOUT, ldap.SERVER_DOWN) as ex:  # catching just ldap.TIMEOUT is not enough!
    log.error("Exception: {0}".format(ex))