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

Re: ITS#3089



A number of paged results bug fixes have been committed
to HEAD and OPENLDAP_REL_ENG_2_2.  Please test.  Thanks, Kurt

At 02:54 AM 6/5/2004, jon@illumining.com wrote:
>This is a multi-part message in MIME format.
>
>------=_NextPart_000_0002_01C44AEB.4CE89F20
>Content-Type: text/plain;
>        charset="iso-8859-1"
>Content-Transfer-Encoding: 7bit
>
>Paging bug from 2.2.5 still present in 2.2.11
>
>The Paged Results Control bug that I mentioned for OpenLdap 2.2.5 still
>appears to be present IN 2.2.11. I recently upgraded from 2.2.5 to 2.2.11
>and ran an old test I had to see if the paged results control stuff now
>worked (java code attached). The test failed in the same manner as it had
>with 2.2.5.
>
>I wouldnt have posted to the list, except some time ago I seem to remember
>someone mentioning that it had been fixed (in 2.2.7 I think). I just thought
>I'd let you know the bug is still there, lurking in the shadows and waiting
>to strike ;-)
>
>Links that may be relevant:
>
>http://www.openldap.org/its/index.cgi/Contrib?id=2189;expression=paging;usea
>rchives=1;statetype=-1
>Looks curiously like what I've been experiencing; beyond getting the first
>page of results I get errors (LDAP code 2 or 53) stating that the cookie is
>invalid or old. LDAP error code 2 always seems to be the error I get the
>first time my test method runs (wrapped by a CommunicationException) and
>LDAP error code 53 always seems to be generated for all subsequent runs of
>the method until the calling program exits.
>
>This looks similar to the problem I've been having:
>http://www.openldap.org/its/index.cgi/Incoming?id=3089;selectid=3089;usearch
>ives=1;statetype=-1
>
>------=_NextPart_000_0002_01C44AEB.4CE89F20
>Content-Type: text/plain;
>        name="testmethod.txt"
>Content-Transfer-Encoding: quoted-printable
>Content-Disposition: attachment;
>        filename="testmethod.txt"
>
>        /* Do not remove this test method or these comments until we get =
>OpenLdap working with paging.
>
>           Currently this method will fail at a random point when retreiving a =
>number of pages one after
>           the other. The failure is reported in the form of an =
>OperationNotSupportedException wrapped around
>           the following Ldap error code:
>          =20
>           [LDAP: error code 53 - paged results cookie is invalid or old]
>          =20
>           A brief search using Google gave me a peice of C source code for =
>OpenLdap, which is ultimately
>           the source of the error:
>          =20
>           =
>http://www.opensource.apple.com/darwinsource/10.3/OpenLDAP-37/OpenLDAP/se=
>rvers/slapd/controls.c
>          =20
>           A copy of the controls.c is available locally. On occasion the start =
>of the error message says=20
>           [LDAP: error code 2..] but the remainder of the message is the same.
>        */  =20
>        public void testLdapPaging() throws Exception
>        {
>                try {
>                =09
>                        //#1 create a naming enumeration to hold the results
>                        NamingEnumeration naming =3D null;
>                =09
>                        //#2 set or retreive the size of the page
>                        int pageSize =3D 2;
>                =09
>                        //#3 determine what the search base is
>                        String searchBase =3D "ou=3DPeople, dc=3Djon, dc=3Dillumining, =
>dc=3Dcom";
>                =09
>                        //#4 get the context object
>                        Hashtable hashtable =3D new Hashtable();
>                        String initCtxFactory =3D "com.sun.jndi.ldap.LdapCtxFactory";
>                        String host =3D "ldap://localhost:389";;
>                        String security =3D "simple";
>                        String dn =3D "cn=3DManager, dc=3Dillumining, dc=3Dcom";
>                        String pwd =3D "secret";                =09
>                        hashtable.put(Context.INITIAL_CONTEXT_FACTORY, initCtxFactory);
>                        hashtable.put(Context.PROVIDER_URL, host);
>                        hashtable.put(Context.SECURITY_AUTHENTICATION, security);
>                        hashtable.put(Context.SECURITY_PRINCIPAL, dn);
>                        hashtable.put(Context.SECURITY_CREDENTIALS, pwd);
>                        hashtable.put("java.naming.ldap.version", "3");
>                        InitialLdapContext ctx =3D new InitialLdapContext(hashtable, null);
>                =09
>                        //#5 create the search controls object
>                        SearchControls controls =3D new SearchControls();
>                        controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
>                =09
>                        //#6 create the paged results control object
>                        PagedResultsControl prc =3D new PagedResultsControl(pageSize);
>                =09
>                        //#7 create the request controls array
>                        Control reqCtls[] =3D new Control[]{prc};
>                =09
>                        //#8 set the request controls array on the context
>                        ctx.setRequestControls(reqCtls);
>                =09
>                        //#9 set what the return attributes will be
>                        String[] returnAttributes =3D {"uid"};
>                        controls.setReturningAttributes(returnAttributes);
>                =09
>                        //#10 create an ldap search filter
>                        String ldapSearchFilter =3D =
>"(&(objectClass=3DinetOrgPerson)(cn=3D*hick*))";
>                =09
>                        //#11 create do while loop variables
>                        int count =3D 0;
>                        byte[] b =3D null;
>                =09
>                        //#12 enter do while loop
>                        do
>                        {
>                                //#13 perform search using search base- search filter and search
>                                naming =3D ctx.search(searchBase, ldapSearchFilter, controls);
>                        =09
>                                //#14 test if NamingEnumeration does not equal null
>                                if(naming !=3D null)
>                                {
>                                        int subcounter =3D 0;
>                                        // You must iterate through the NamingEnumeration, even if its not =
>the one you want-
>                                        // and you want a subsequent page. For some reason if you dont =
>iterate through the=20
>                                        // NamingEnumeration a server-side cookie is NOT created, which =
>means you cant access
>                                        // the subsequent pages by obtaining a PagedResultsResponseControl =
>and getting a cookie
>                                        // from it.
>                                        while(naming.hasMoreElements())
>                                        {
>                                                subcounter++;
>                                                SearchResult si =3D (SearchResult)naming.nextElement();
>                                                count++;
>                                                System.out.println(si.getName());
>                                        }
>                                        System.out.println(ldapSearchFilter + " returned " + subcounter );
>                                }
>                                else                   =20
>                                {
>                                        System.out.println(ldapSearchFilter + " did not return any =
>entries.");
>                                }
>                        =09
>                                //#15 check if the response controls are null
>                                Control[] response =3D ctx.getResponseControls();
>                                if(response !=3D null)
>                                {=09
>                                        b =3D((PagedResultsResponseControl)response[0]).getCookie();
>                                }
>                                else
>                                {
>                                        b =3D null;
>                                }
>                                if(b !=3D null)
>                                {
>                                        //print out cookie info
>                                        System.out.println("Got cookie: ");
>                                        for(int i =3D 0; i < b.length; i++)
>                                        {
>                                                System.out.println("Byte "+i+" =3D "+ b[i]);
>                                        }
>                                =09
>                                        //create new PagedResultsControl
>                                        prc =3D new PagedResultsControl(pageSize, b, Control.CRITICAL);
>                                        ctx.setRequestControls(new Control[] {prc});
>                                }=09
>                        =09
>                        }while(b !=3D null);
>                        //added this to see if it made any difference
>                        naming.close();
>                        ctx.close();
>                } catch (NamingException e) {
>                        e.printStackTrace();
>                        throw new Exception();
>                } catch (IOException e) {
>                        e.printStackTrace();
>                        throw new Exception();
>                }
>        }
>------=_NextPart_000_0002_01C44AEB.4CE89F20
>Content-Type: text/plain;
>        name="STACK.txt"
>Content-Transfer-Encoding: quoted-printable
>Content-Disposition: attachment;
>        filename="STACK.txt"
>
>FIRST EXAMPLE STACK TRACE AND STDOUT- FAILURE ON AN ATTEMPT TO GET THE =
>SECOND PAGE
>
>uid=3DAhab12345678
>uid=3DAbraham12345678
>(&(objectClass=3DinetOrgPerson)(cn=3D*hick*)) returned 2
>Got cookie:
>Byte 0 =3D 22
>Byte 1 =3D -4
>Byte 2 =3D 0
>Byte 3 =3D 0
>javax.naming.CommunicationException: [LDAP: error code 2 - paged results =
>cookie is invalid]; remaining name 'ou=3DPeople, dc=3Djon, =
>dc=3Dillumining, dc=3Dcom'
>        at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3036)
>        at =
>com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2934)
>        at =
>com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2740)
>        at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1811)
>        at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1734)
>        at =
>com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext=
>.java:368)
>        at =
>com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialComposi=
>teDirContext.java:328)
>        at =
>com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialComposi=
>teDirContext.java:313)
>        at =
>javax.naming.directory.InitialDirContext.search(InitialDirContext.java:23=
>8)
>        at =
>com.illumining.server.persistence.ldap.LdapUserDAO.testLdapPaging(LdapUse=
>rDAO.java:1002)
>        at com.illumining.server.UserService.test(UserService.java:885)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at =
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java=
>:39)
>        at =
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI=
>mpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:324)
>        at =
>sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
>        at sun.rmi.transport.Transport$1.run(Transport.java:148)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
>        at =
>sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
>        at =
>sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.jav=
>a:701)
>        at java.lang.Thread.run(Thread.java:534)
>
>
>
>SECOND EXAMPLE STDOUT AND STACK TRACE BELOW- FAILURE ON AN ATTEMPT TO =
>GET THE THIRD PAGE OF RESULTS
>
>uid=3DAhab12345678
>uid=3DAbraham12345678
>(&(objectClass=3DinetOrgPerson)(cn=3D*hick*)) returned 2
>Got cookie:
>Byte 0 =3D 99
>Byte 1 =3D -4
>Byte 2 =3D 0
>Byte 3 =3D 0
>uid=3DAlice12345678
>uid=3DBilly-Bob12345678
>(&(objectClass=3DinetOrgPerson)(cn=3D*hick*)) returned 2
>Got cookie:
>Byte 0 =3D 105
>Byte 1 =3D -4
>Byte 2 =3D 0
>Byte 3 =3D 0
>javax.naming.OperationNotSupportedException: [LDAP: error code 53 - =
>paged results cookie is invalid or old]; remaining name 'ou=3DPeople, =
>dc=3Djon, dc=3Dillumining, dc=3Dcom'
>        at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3061)
>        at =
>com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2934)
>        at =
>com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2740)
>        at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1811)
>        at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1734)
>        at =
>com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext=
>.java:368)
>        at =
>com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialComposi=
>teDirContext.java:328)
>        at =
>com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialComposi=
>teDirContext.java:313)
>        at =
>javax.naming.directory.InitialDirContext.search(InitialDirContext.java:23=
>8)
>        at =
>com.illumining.server.persistence.ldap.LdapUserDAO.testLdapPaging(LdapUse=
>rDAO.java:1002)
>        at com.illumining.server.UserService.test(UserService.java:885)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at =
>sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java=
>:39)
>        at =
>sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI=
>mpl.java:25)
>        at java.lang.reflect.Method.invoke(Method.java:324)
>        at =
>sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
>        at sun.rmi.transport.Transport$1.run(Transport.java:148)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
>        at =
>sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
>        at =
>sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.jav=
>a:701)
>        at java.lang.Thread.run(Thread.java:534)
>------=_NextPart_000_0002_01C44AEB.4CE89F20--