title: Increasing LDAP Query timeout value
body: <p>I am using an Active Directory Server and a java client with a Spring-Ldap library to do LdapTemplate.search (for doing ldapSearch on AD). The exception I am getting is below which is because of my query times out. I can't change my baseDN and filters so looking for other options i.e to increase LDAP Search Query timeout value on AD:</p>
  
  <p>ERROR - ></p>
  
  <pre><code>Internal Server Error; Caused by
  org.springframework.ldap.TimeLimitExceededException: [LDAP: error code 3 - Timelimit Exceeded]; nested exception is javax.naming.TimeLimitExceededException: [LDAP: error code 3 - Timelimit Exceeded]; remaining name DC=XX,DC=YY,DC=COM
  at  org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:160)
          at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:397)
          at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:328)
          at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:604)
          at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:594)
          at 
  </code></pre>
  
  <p>On Client (Java/Spring-Ldap) I have increased the value of SearchControls(timeLimit) and even com.sun.jndi.ldap.read.timeout but seems like it didn't help. Still getting TimeOut Exception. Is there something on the Active Directory server side to increase the search query timeout value. 
  I am not even sure if its the Active Directory server which timeout or is it the Java client, based on the error I am seeing in the logs as shared above.</p>
  
  <pre><code>LDAPTEMPLATE Search API code
  
  public void search(SearchExecutor se, NameClassPairCallbackHandler handler, DirContextProcessor processor) {
          DirContext ctx = contextSource.getReadOnlyContext();
  
          NamingEnumeration results = null;
          RuntimeException ex = null;
          try {
              processor.preProcess(ctx);
              results = se.executeSearch(ctx);
  
              while (results.hasMore()) {
                  NameClassPair result = (NameClassPair) results.next();
                  handler.handleNameClassPair(result);
              }
          }
  </code></pre>