[Date Prev][Date Next] [Chronological] [Thread] [Top]

JLDAP: No results on multiple synchronous searches

I've got something of an odd problem here.  If I run the following Java:


import com.novell.ldap.*;

public class TestLDAP {
    public TestLDAP () {

    public static void main (String args[]) {
        LDAPConnection  ldap    = null;
        try {
            ldap    = new LDAPConnection ();
            ldap.connect ("ldap-test", 389);
            ldap.bind (LDAPConnection.LDAP_V3, "uid=user,o=basedn", (new String ("password")).getBytes());

            LDAPSearchResults   r   = ldap.search ("o=basedn",
                                                   LDAPConnection.SCOPE_BASE, "(objectclass=*)", null, false);
            System.err.println ("First search: " + r.getCount () + " results found.");

            LDAPSearchResults   r2   = ldap.search ("o=basedn",
                                                   LDAPConnection.SCOPE_BASE, "(objectclass=*)", null, false);
            System.err.println ("Second search: " + r2.getCount () + " results found.");
        } catch (LDAPException e){ 
            System.err.println (e);

        System.err.println ("Done.");


I get the following:

First search: 1 results found.
Second search: 0 results found.

... which is not what I expect.  However, if I insert something as simple
as a Thread.sleep (100) before the println, I get the expected '1'.

However again, if I throw in a System.err.println (r.next ()); after each
search, the first will print out the entry, and the second will error with:

LDAPException: LDAPSearchResults.next(): No entry found & request is not complete (82) Local Error

... regardless of the delay.  To make matters even more confusing, if I
take the same code and run it on another machine (FreeBSD as opposed to
Linux), then BOTH searches will produce no results.

What am I doing wrong?  I can't produce this behaviour with the equivalent
code in Perl with Net::LDAP.  I'm running against OpenLDAP 2.2.23, which I
realize is old but can't be upgraded right now.  I'm using JLDAP built
from source from CVS as of 2006/06/29 11:00 ADT.

The fact that the two queries are the same doesn't appear to matter.  I
just use the same queries to show that one succeeds while the other does