[
https://issues.apache.org/jira/browse/DIRAPI-342?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16835535#comment-16835535
]
Emmanuel Lecharny commented on DIRAPI-342:
------------------------------------------
Ok, so any closed socket will stay in {{TIME_WAIT}} for 60 seconds - which is
ok - and you will be able to create 1000 file descriptors - which is quite low
-.
The {{SO_LINGER}} parameter is of little use. It will just make it so that a
socket can be closed brutally. On the server, it's more important to set the
{{SO_REUSEADDR}} flag which allows thee reuse of sockets.
But bottom line, when you run the loop, it takes something like 3ms to
establish a connection, bind and unbind, which means you can only loop 18 000
times with the {{TIME_WAIT}} set to 60 seconds (60 * 1/0.003), and you will
exhaust your file descriptors in less than that, simply because many are
already in use when you start the test (I typically have 800 FD used on my
laptop). One way to check teh FD exhaustion is to periodically run {{netstat
-na | wc -l}}.
There is nothing you can do about sockets waiting in {{TIME_WAIT}} state (see
https://dvas0004.files.wordpress.com/2010/07/state_diag.png), the socket will
wait 2 times the configured MSL, no matter what. The only way to augment the
number of sockets you can open is to change the {{ulimit}} parameter.
Side note: it's clearly not recommanded to change the MSL parameter on a
machine, that would impact *all* the applications. Changing the ulimit though
can be done either for the system or for the user running the tests (although
there are two existing limits, the OS limit blocks the user limits).
The question is why adding a 2ms sleep helps. Note that sleep(2) will not
necessarily wait 2ms.
I will install a linux VLM to do some more tests.
> Unbind breaks connection
> ------------------------
>
> Key: DIRAPI-342
> URL: https://issues.apache.org/jira/browse/DIRAPI-342
> Project: Directory Client API
> Issue Type: Bug
> Affects Versions: 2.0.0.AM2
> Reporter: Stefan Seelmann
> Priority: Major
> Fix For: 2.0.0.AM3, 2.0.0
>
>
> The DelegatedAuthIT/DelegatedAuthOverSslIT/DelegatedAuthOverTlsIT tests fail
> randomly (I try to stabilize tests on Windows, but also happens on Jenkins).
> They all do multiple bind() and unbind() on the same connection, it seems the
> unbind() is the reason.
> A simple test to reproduce the problem (on Linux):
> {code}
> @Test
> public void testSimpleBindAndUnbindLoop() throws Exception
> {
> try ( LdapConnection connection = new LdapNetworkConnection(
> Network.LOOPBACK_HOSTNAME,
> getLdapServer().getPort() ) )
> {
> for ( int i = 0; i < 10000; i++ )
> {
> System.out.println( i );
> connection.bind( "uid=admin,ou=system", "secret" );
> assertTrue( connection.isAuthenticated() );
> connection.unBind();
> assertFalse( connection.isAuthenticated() );
> // Thread.sleep( 10L );
> }
> }
> }
> {code}
> Without the unbind() or when sleeping for 10ms it works fine.
> Otherwise I saw 3 different errors:
> {code}
> org.apache.directory.ldap.client.api.exception.InvalidConnectionException:
> ERR_04108_INVALID_CONNECTION Cannot connect on the server, the connection is
> invalid
> at
> org.apache.directory.ldap.client.api.LdapNetworkConnection.checkSession(LdapNetworkConnection.java:574)
> at
> org.apache.directory.ldap.client.api.LdapNetworkConnection.bindAsync(LdapNetworkConnection.java:1596)
> at
> org.apache.directory.ldap.client.api.LdapNetworkConnection.bind(LdapNetworkConnection.java:1488)
> at
> org.apache.directory.ldap.client.api.AbstractLdapConnection.bind(AbstractLdapConnection.java:134)
> at
> org.apache.directory.ldap.client.api.AbstractLdapConnection.bind(AbstractLdapConnection.java:118)
> {code}
> {code}
> org.apache.directory.api.ldap.model.exception.LdapException:
> ERR_04169_RESPONSE_QUEUE_EMPTIED The response queue has been emptied, no
> response was found.
> at
> org.apache.directory.ldap.client.api.LdapNetworkConnection.bind(LdapNetworkConnection.java:1534)
> at
> org.apache.directory.ldap.client.api.AbstractLdapConnection.bind(AbstractLdapConnection.java:134)
> at
> org.apache.directory.ldap.client.api.AbstractLdapConnection.bind(AbstractLdapConnection.java:118)
> Caused by: org.apache.directory.api.ldap.model.exception.LdapException:
> ERR_04170_TIMEOUT_OCCURED TimeOut occurred
> at
> org.apache.directory.ldap.client.api.LdapNetworkConnection.bind(LdapNetworkConnection.java:1505)
> {code}
> {code}
> org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException:
> PROTOCOL_ERROR: The server will disconnect!
> at
> org.apache.directory.api.ldap.model.message.ResultCodeEnum.processResponse(ResultCodeEnum.java:2137)
> at
> org.apache.directory.ldap.client.api.AbstractLdapConnection.bind(AbstractLdapConnection.java:136)
> at
> org.apache.directory.ldap.client.api.AbstractLdapConnection.bind(AbstractLdapConnection.java:118)
> at
> org.apache.directory.shared.client.api.operations.bind.SimpleBindRequestTest.testSimpleBindAndUnbindLoop(SimpleBindRequestTest.java:664)
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)