Search code examples
javaldapunboundid-ldap-sdk

LDAP Response timeout not working with Unboundid SDK


I am trying to get the names of all groupOfUniqueNames objects using the Unboundid LDAP SDK. I am able to do it, but have a problem if the server has a lot of entries. Setting the response timeout seems to be ignored, and the program just hangs (waiting for the large response), instead of terminating after 5000 milliseconds.

I have come to understand that I can use paging to return a certain amount of users at a time, however, I am concerned as to why the timeout isn't working.

SearchResult searchResult;

    Filter filter = 
            Filter.createEqualityFilter("objectClass", "groupOfUniqueNames");

    try {
        SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, filter, "uniqueMember", "member");

        searchRequest.setResponseTimeout(5000);
        System.out.println(searchRequest.getResponseTimeout(connection));   // prints 5000

        searchResult = connection.search(searchRequest);

    } catch(LDAPSearchException e) {
        e.printStackTrace();
    }

    for (SearchResultEntry entry : searchResult.getSearchEntries()) {
        String name = entry.getDN();
        System.out.println(name);
    }

What is perplexing to me is that the above code will always hang, however I've had other searches that timeout properly (with error 85 - client timeout).

What could the reason be for this particular query ignoring the client timeout? The documentation here makes it sound like, no matter what, after 5000 milliseconds the program will stop waiting for a response.

Thank you


Solution

  • I had the similar problem:

    LDAP Error Code 85 - A client-side timeout was encountered
    

    In my case I had to configure SSL for LDAP connection. For example, see this as temp implementation:

     SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
     SSLSocketFactory sslSocketFactory = sslUtil.createSSLSocketFactory();
     LDAPConnection connection = new LDAPConnection(sslSocketFactory);
    

    https://docs.ldap.com/ldap-sdk/docs/javadoc/com/unboundid/util/ssl/SSLUtil.html

    I think that words about "timeout" are very confusing in that case.