Menu

Search query timesout, setting new timeout for the same connection

2013-11-08
2013-11-18
  • www.pakistanandroid.com

    Hi Neil,

    Is it possible to set connection option with new timeout if a search request with same connection fails after a timeout? I mean when a search request fails after a timeout, an exception is thrown and while catching exception we set the new timeout to the same connection and retry search. I think it should be possible?

     
  • Neil Wilson

    Neil Wilson - 2013-11-08

    Yes, you should be able to update the connection options and perform the search again. But if you want to issue just that one search with a different timeout, you could also use the SearchRequest.setResponseTimeMillis method to set the timeout just for that request without changing the connection options for the whole connection.

     
    • www.pakistanandroid.com

      Hi Neil,

      Its a stupid question but i might not be interpreting right.

      Using below method, setting responseTimeout to 0 will block the operations on the connection for a indefinite time, till it receives reply from server?

      public void setResponseTimeoutMillis(long responseTimeout)

      Thanks

       
      • Neil Wilson

        Neil Wilson - 2013-11-11

        Yes, a timeout of zero means no timeout. However, I would recommend a really long timeout rather than no timeout at all, since if the server never sends a response for an operation (e.g., an internal server error was encountered while processing the operation, if the operation is silently abandoned, etc.), then the client could block forever.

         
        • www.pakistanandroid.com

          Hi Neil,

          I have got few issues. I am using a connection from connection pool. The connection pool has already options set like timeout of 10000 ms etc.

          In my last post i mentioned that i set the connection option for a individual connection from pool to unlimited and after it finished its task i released the connection to the pool again. So it worked and i released the connection back to pool.

          Then,

          I tried to search for a record in data base with a new connection from pool and during that time i closed the connection between my computer and ldap server. The search query was stuck there for a long time (I was expecting that it should timeout after 10s/10000ms) and as soon as i enabled the connection between my pc and ldap server the results were retrieved. Very Weird ?

          Is it possible that setting connection option to only one individual connection from pool can cause to set the options on the whole connection pool? or you release connection to the pool, is it possible that next time if the connection is fetched from pool it may have the new (unlimited timeout) option set?

          About this search query:

          Do it has some sort of sleep time when it tries once to search for record in ldap and if it doesn't get anything then sleeps for some time and retries again?

          Will appreciate your comments. Thank you.

           
          • Neil Wilson

            Neil Wilson - 2013-11-14

            Changing the response timeout for one connection in a connection pool will not cause it to be applied to all other connections in the pool, but that timeout will continue to be applied for subsequent operations processed on that connection. It is likely the case if you previously set a very long or unlimited timeout on a connection, then the problem you are seeing is a result of that connection being used in this case.

            It is strongly recommended that you not do anything to a connection in a connection pool that may change the state of that connection in a way that is not consistent with other connections in the pool. As such, if you need to change the response timeout for a particular operation, you should either set the timeout on the specific request rather than making it the default timeout for all operations on that connection (e.g., if you are processing a search request, then use the SearchRequest.setResponseTimeoutMillis method) or if there is a compelling reason to use the LDAPConnectionOptions.setResponseTimeoutMillis method to set the default response timeout for a connection you have checked out of the pool, then you should change the default response timeout for the connection back to what it was before returning that connection to the pool.

             
  • www.pakistanandroid.com

    Thank you very much Neil. Appreciated :)

     
  • www.pakistanandroid.com

    During search query we have unplugged connection and an exception is thrown after timeout. Why it didn't threw exception immediately or is a normal behaviour? It happened in our case.

    A connection was created from pool. A search query was made and at the same time network cable was unplugged. The search query stucked there till timeout and then an exception was thrown. We were expecting it to throw exception immediately.

     
    • Neil Wilson

      Neil Wilson - 2013-11-15

      From your description, it sounds like the LDAP SDK waited for the configured timeout before throwing an exception. If that's the case, then I presume that everything is working properly.

      When the LDAP SDK sends a request, it should immediately fail if there is a problem sending the request. However, the JVM and/or underlying OS may not have actually waited for the TCP acknowledgement that the request was actually received by the server. If this is the case and there is still room in the socket's transmit buffer, then it's possible that the JVM didn't report any failure when sending a request that didn't actually get sent. If this is the case, then I expect sending a lot of outstanding requests on the same connection (either by using multiple threads or using the asynchronous API) would eventually fill up the transmit buffer so that further attempts to send requests would fail or block because the buffer is full.

      If the JVM had reported a failure back to the LDAP SDK when trying to send the request, then the LDAP SDK would have immediately thrown an exception. If the JVM doesn't report this failure but behaves as if the request were sent, then there's no way that the LDAP SDK would have to know that might not have actually been the case.

       
  • www.pakistanandroid.com

    If i have 10 s timeout for a connection and a search request has timeout set to 60 s, then what would be the effect of searching with the connection which has 10.?

    connection has timeout 10s.
    Search request has timeout 60s.
    SearchRequest req = new ....
    req.setResponseTimeoutMillis(60000);
    connection.search(req);

    Will it timeout after 10 second or 60 seconds.?

    Thanks

     
    • Neil Wilson

      Neil Wilson - 2013-11-18

      The search would have a timeout of sixty seconds. If you set a timeout on a request, it overrides the timeout set in the connection options that would have otherwise been used.

       

Log in to post a comment.