You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Hendy Irawan (JIRA)" <ji...@apache.org> on 2012/11/28 04:53:03 UTC
[jira] [Commented] (DIRAPI-97) Unreliable LdapConnectionPool:
org.apache.directory.ldap.client.api.exception.InvalidConnectionException:
Cannot connect on the server, the connection is invalid
[ https://issues.apache.org/jira/browse/DIRAPI-97?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13505208#comment-13505208 ]
Hendy Irawan commented on DIRAPI-97:
------------------------------------
BTW this was how I did it :
{code}
public static <V> V withConnection(@Nonnull final ObjectPool<LdapConnection> ldapPool, @Nonnull final Function<LdapConnection, V> function) {
try {
final LdapConnection conn = ldapPool.borrowObject();
try {
return function.apply(conn);
} finally {
ldapPool.returnObject(conn);
}
} catch (Exception e) {
log.error("LDAP operation error", e);
Throwables.propagate(e);
return null;
}
}
{code}
That code can trigger this exception.
I am now trying another variant, will this work as expected?
{code}
public static <V> V withConnection(@Nonnull final ObjectPool<LdapConnection> ldapPool, @Nonnull final Function<LdapConnection, V> function) {
final LdapConnection conn;
try {
conn = ldapPool.borrowObject();
} catch (Exception e) {
throw new RuntimeException("Cannot get LDAP connection", e);
}
try {
V result = function.apply(conn);
ldapPool.returnObject(conn);
return result;
} catch (Exception e) {
try {
ldapPool.invalidateObject(conn);
} catch (Exception e1) {
log.warn("Cannot invalidate LDAP connection after " + e + " exception", e1);
}
throw new RuntimeException("Cannot perform LDAP operation", e);
}
}
{code}
If this error is by design, then some documentation should be provided on how to use LdapConnectionPool properly.
> Unreliable LdapConnectionPool: org.apache.directory.ldap.client.api.exception.InvalidConnectionException: Cannot connect on the server, the connection is invalid
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: DIRAPI-97
> URL: https://issues.apache.org/jira/browse/DIRAPI-97
> Project: Directory Client API
> Issue Type: Bug
> Affects Versions: 1.0.0-M13
> Environment: Karaf
> Karaf version 2.3.0
> Karaf home /home/karaf/karaf
> Karaf base /home/karaf/karaf
> OSGi Framework org.apache.felix.framework - 4.0.3
> JVM
> Java Virtual Machine Java HotSpot(TM) Server VM version 23.5-b02
> Version 1.7.0_09
> Vendor Oracle Corporation
> Uptime 4 days 7 hours
> Total compile time 54.019 seconds
> Threads
> Live threads 119
> Daemon threads 92
> Peak 149
> Total started 3151
> Memory
> Current heap size 63,365 kbytes
> Maximum heap size 506,816 kbytes
> Committed heap size 126,912 kbytes
> Pending objects 0
> Garbage collector Name = 'Copy', Collections = 970, Time = 6.659 seconds
> Garbage collector Name = 'MarkSweepCompact', Collections = 111, Time = 31.891 seconds
> Classes
> Current classes loaded 13,396
> Total classes loaded 15,142
> Total classes unloaded 1,746
> Operating system
> Name Linux version 3.6.5-linode47
> Architecture i386
> Processors 4
> Reporter: Hendy Irawan
> Priority: Critical
>
> We use LdapConnectionPool exclusively in order to increase performance without sacrificing stability.
> However, it seems that it's possible to break this and will cause :
> {code}
> Caused by: org.apache.directory.shared.ldap.model.exception.LdapException: org.apache.directory.ldap.client.api
> .exception.InvalidConnectionException: Cannot connect on the server, the connection is invalid
> at org.apache.directory.ldap.client.api.LdapNetworkConnection.lookup(LdapNetworkConnection.java:3169)
> at org.apache.directory.ldap.client.api.LdapNetworkConnection.lookup(LdapNetworkConnection.java:3181)
> at org.apache.directory.ldap.client.api.LdapNetworkConnection.lookup(LdapNetworkConnection.java:3116)
> at id.co.bippo.shop.LdapShopDao$1.apply(LdapShopDao.java:88)
> ... 78 more
> Caused by: org.apache.directory.ldap.client.api.exception.InvalidConnectionException: Cannot connect on the ser
> ver, the connection is invalid
> at org.apache.directory.ldap.client.api.LdapNetworkConnection.checkSession(LdapNetworkConnection.java:2
> 72)
> at org.apache.directory.ldap.client.api.LdapNetworkConnection.searchAsync(LdapNetworkConnection.java:15
> 48)
> at org.apache.directory.ldap.client.api.LdapNetworkConnection.search(LdapNetworkConnection.java:1586)
> at org.apache.directory.ldap.client.api.LdapNetworkConnection.lookup(LdapNetworkConnection.java:3151)
> ... 81 more
> {code}
> When it gets to this state, repeated calls to borrowObject/returnObject seem to return the same invalid connection(s).
> I can think of several reason why the connection was invalidated: LDAP connection breaks, LDAP server was restarted, but can be anything, really. However, I expect the pool would handle this, and purge invalid connections automatically.
> So that when ldapPool.borrowObject(); is called, the LdapConnection given should be valid & ready to use.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira