[
https://issues.apache.org/jira/browse/DIRAPI-358?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17233012#comment-17233012
]
contrabass22 commented on DIRAPI-358:
-------------------------------------
I have encountered this bug as well and have a potential fix, pending review.
When the LDAP server is down LdapNetworkConnection.tryConnect() and
LdapNetworkConnection.connect() leak file descriptors.
In tryConnect() the connector is set to null without first releasing its
resources.
In connect() there is a call to createConnector(), which may throw an exception
without releasing the connector resources.
Here's the patch:
{noformat}
---
a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
+++
b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
@@ -692,6 +692,9 @@ public class LdapNetworkConnection extends
AbstractLdapConnection implements Lda
// It may be an exception, or a timeout
Throwable connectionException = connectionFuture.getException();
+ if (connector != null && !connector.isDisposing() &&
!connector.isDisposed())
+ connector.dispose();
+
connector = null;
if ( connectionException == null )
@@ -933,6 +936,7 @@ public class LdapNetworkConnection extends
AbstractLdapConnection implements Lda
return true;
}
+ try {
// Create the connector if needed
if (connector == null)
{
@@ -974,6 +978,15 @@ public class LdapNetworkConnection extends
AbstractLdapConnection implements Lda
// And return
return true;
}
+ catch (Exception e) {
+ if (connector != null && !connector.isDisposing() &&
!connector.isDisposed()) {
+ connector.dispose();
+ connector = null;
+ }
+
+ throw e;
+ }
+ }
{noformat}
> File Descriptor leak on connection failure with LdapConnectionTemplate
> ----------------------------------------------------------------------
>
> Key: DIRAPI-358
> URL: https://issues.apache.org/jira/browse/DIRAPI-358
> Project: Directory Client API
> Issue Type: Bug
> Affects Versions: 2.0.0.AM4, 2.0.0, 2.0.1
> Reporter: Natan Abolafya
> Priority: Major
>
> Seems to have appeared on AM4.
>
> We had two instances crashing after half an hour outage on the LDAP server
> because the process ran out of file descriptor limit.
>
>
> {noformat}
> var template = createLdapConnectionTemplate();
> template.searchFirst(....);
> {noformat}
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]