title: java LDAP read timeout when timeout is not reached?
body: <p>I have a Java application that connects to an LDAP using LDAPContext. Below are my environment properties:</p>
  
  <pre><code>    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
      env.put("com.sun.jndi.ldap.read.timeout", READ_TIMEOUT);
      env.put("com.sun.jndi.ldap.connect.timeout", CONNECTION_TIMEOUT);
      env.put(Context.PROVIDER_URL, host);
      if (principal == null || principal.isEmpty()) {
        env.put(Context.SECURITY_AUTHENTICATION, "none");
      } else {
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, principal + "@" + domain);
        env.put(Context.SECURITY_CREDENTIALS, password);
      }
      if (useLDAPS) {
        env.put(Context.SECURITY_PROTOCOL, "ssl");
      }
  </code></pre>
  
  <p>The problem I have been encountering lately is every once in a while when attempting to connect, I get a read timeout error before the timeout time has been reached. The timeout is set to 10000ms (10 seconds). I have even tried removing the property that sets the timeout and it still occurs.</p>
  
  <p>Are there other reasons this could be happening? If the connection gets reset due to something like max connections being reached, does it throw a read timeout? The exception I am seeing is:</p>
  
  <pre><code>javax.naming.CommunicationException: XX.XX.XX.XX:636 [Root exception is java.net.SocketTimeoutException: Read timed out]
          at com.sun.jndi.ldap.Connection.&lt;init&gt;(Connection.java:226)
  </code></pre>
  
  <p><strong>Update 9/15/15</strong>
  Still having this issue. Here is the stack trace. Any help is appreacited.</p>
  
  <pre><code>WARNING: CommunicationException
  javax.naming.CommunicationException: XX.XX.XX.XX:636 [Root exception is java.net.SocketTimeoutException: Read timed out]
         at com.sun.jndi.ldap.Connection.&lt;init&gt;(Connection.java:226)
         at com.sun.jndi.ldap.LdapClient.&lt;init&gt;(LdapClient.java:136)
         at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1608)
         at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2698)
         at com.sun.jndi.ldap.LdapCtx.&lt;init&gt;(LdapCtx.java:316)
         at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:193)
         at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:211)
         at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
         at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
         at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
         at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
         at javax.naming.InitialContext.init(InitialContext.java:242)
         at javax.naming.ldap.InitialLdapContext.&lt;init&gt;(InitialLdapContext.java:153)
         at my.package.name.ToolClass.getLdapConnection(ToolClass.java:302)
  Caused by: java.net.SocketTimeoutException: Read timed out
         at java.net.SocketInputStream.socketRead0(Native Method)
         at java.net.SocketInputStream.read(SocketInputStream.java:152)
         at java.net.SocketInputStream.read(SocketInputStream.java:122)
         at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
         at sun.security.ssl.InputRecord.read(InputRecord.java:480)
         at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:934)
         at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
         at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
         at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
         at com.sun.jndi.ldap.Connection.createSocket(Connection.java:381)
         at com.sun.jndi.ldap.Connection.&lt;init&gt;(Connection.java:203)
         ... 27 more
  </code></pre>