Anonymous_User Absent Member.
Absent Member.
383 views

JLDAP - Timeout not working inside connect()


Hi,

I have been searching this problem for a while, but I cannot find
anything.

I have a list of Ldap servers to connect to, and some of them are down.
I set the timeout of the LDAPConnection with this code:

Code:
--------------------
LDAPConnection lc = new LDAPConnection(connTimeout);
LDAPConstraints lcons = new LDAPConstraints();

lcons.setTimeLimit(connTimeout);
lc.getSearchConstraints().setTimeLimit(connTimeout);
lc.getSearchConstraints().setServerTimeLimit(connTimeout);
lc.setConstraints(lcons);
--------------------


The problem is that timeout does not work within this invocation:

Code:
--------------------
lc.connect(this.ip, this.port);
--------------------

After 21000 ms (I made several measures and all are around 21000 +/- 50
ms) this method throws an LDAPException saying that the connection is
timed out, although I was using 5000 ms for timeout. So, it throws the
right exception, but in an incorrect time.

Please help!
Thanks in advance for your time.

Regards,
Juan Ignacio


--
jigarzon
------------------------------------------------------------------------
jigarzon's Profile: http://forums.novell.com/member.php?userid=95031
View this thread: http://forums.novell.com/showthread.php?t=421745

Labels (1)
0 Likes
4 Replies
jwilleke Trusted Contributor.
Trusted Contributor.

Re: JLDAP - Timeout not working inside connect()

What is the intent?

Are you trying to detect a timed out connection or a downed server or both?

We typically do a try

-jim

On 9/24/10 10:06 AM, jigarzon wrote:
>
> Hi,
>
> I have been searching this problem for a while, but I cannot find
> anything.
>
> I have a list of Ldap servers to connect to, and some of them are down.
> I set the timeout of the LDAPConnection with this code:
>
> Code:
> --------------------
> LDAPConnection lc = new LDAPConnection(connTimeout);
> LDAPConstraints lcons = new LDAPConstraints();
>
> lcons.setTimeLimit(connTimeout);
> lc.getSearchConstraints().setTimeLimit(connTimeout);
> lc.getSearchConstraints().setServerTimeLimit(connTimeout);
> lc.setConstraints(lcons);
> --------------------
>
>
> The problem is that timeout does not work within this invocation:
>
> Code:
> --------------------
> lc.connect(this.ip, this.port);
> --------------------
>
> After 21000 ms (I made several measures and all are around 21000 +/- 50
> ms) this method throws an LDAPException saying that the connection is
> timed out, although I was using 5000 ms for timeout. So, it throws the
> right exception, but in an incorrect time.
>
> Please help!
> Thanks in advance for your time.
>
> Regards,
> Juan Ignacio
>
>

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: JLDAP - Timeout not working inside connect()


jwilleke;2027492 Wrote:
> What is the intent?
>
> Are you trying to detect a timed out connection or a downed server or
> both?
>
> We typically do a try

I have a few servers in a list, and I have to resolve an authentication
by using them. If the first is down, I have to check the second, and so
on. But if timeouts take 20 seconds, its not useful.

I have found a solution. The problem was in the constructor of the Java
Socket used by JLDAP. In the default socket implementation there is no
check for timeouts in constructor, and If the server is unreachable it
hangs for a while. I solved it by providing a custom SocketFactory that
does the check.

Regards and Thanks for your response!


--
jigarzon
------------------------------------------------------------------------
jigarzon's Profile: http://forums.novell.com/member.php?userid=95031
View this thread: http://forums.novell.com/showthread.php?t=421745

0 Likes
jwilleke Trusted Contributor.
Trusted Contributor.

Re: JLDAP - Timeout not working inside connect()

Yes, we had to do that when we did a connection pool using JLDAP.

You may need to verify that this still works with SSL/TLS as we had
different results when security was enabled than when it was not.

We also have used some checks to test:
// connect to the server
ld.connect(ldapHost, ldapPort);
// check connection
System.out.println("is Connected: " + ld.isConnected());
System.out.println("is Bound: " + ld.isBound());
// bind to the server
ld.bind(ldapVersion, loginDN, password.getBytes("UTF8"));
System.out.println("Login succeeded");
// check connection
System.out.println("is Connected: " + ld.isConnected());
System.out.println("is Bound: " + ld.isBound());

Finally, as there has been so little enhancements to the JLDAP library,
we have used the Unboundid SKD which has some added features as their:

ServerSet:
http://www.unboundid.com/products/ldapsdk/docs/javadoc/com/unboundid/ldap/sdk/ServerSet.html

ConnectionPool:
http://www.unboundid.com/products/ldapsdk/docs/javadoc/com/unboundid/ldap/sdk/LDAPConnectionPool.html

-jim

On 9/28/10 9:06 AM, jigarzon wrote:
>
> jwilleke;2027492 Wrote:
>> What is the intent?
>>
>> Are you trying to detect a timed out connection or a downed server or
>> both?
>>
>> We typically do a try

> I have a few servers in a list, and I have to resolve an authentication
> by using them. If the first is down, I have to check the second, and so
> on. But if timeouts take 20 seconds, its not useful.
>
> I have found a solution. The problem was in the constructor of the Java
> Socket used by JLDAP. In the default socket implementation there is no
> check for timeouts in constructor, and If the server is unreachable it
> hangs for a while. I solved it by providing a custom SocketFactory that
> does the check.
>
> Regards and Thanks for your response!
>
>

0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: JLDAP - Timeout not working inside connect()


Jim, thanks a lot for your responses. I will check that library. Thanks
also for your suggestion for SSL, I had some problems with that because
I have to use a different socket implementation, but I think its working
now.

Greetings,
Juan Ignacio


--
jigarzon
------------------------------------------------------------------------
jigarzon's Profile: http://forums.novell.com/member.php?userid=95031
View this thread: http://forums.novell.com/showthread.php?t=421745

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.