Spring LDAP connection pool - file handles not closed when using MutablePoolingContextSource

2k views Asked by At

When using the spring ldap connection pool, I continuously get the following exception. LDAP connections are anyway established and everything works fine at a first glance until finally tomcat hangs after exceeding file handle size limit because obviously sockets are not closed. Any ideas why this issue happens and how to fix it?

Thanks and br, Elmar

Spring exception:

121295 [Timer-2] INFO org.springframework.ldap.pool.validation.DefaultDi rContextValidator []- DirContext 'javax.naming.ldap.InitialLdapContext@5034d0fe' failed validation.
121295 [Timer-2] WARN org.springframework.ldap.pool.validation.DefaultDi rContextValidator []- DirContext 'javax.naming.ldap.InitialLdapContext@432d76f2' failed validation with an exception.
javax.naming.CommunicationException: Connection reset [Root exception is java.net.SocketException: Connection reset]; remaining name ''
    at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:20 03)
    at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1 847)
    at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:17 72)
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_sea rch(ComponentDirContext.java:386)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContex t.search(PartialCompositeDirContext.java:356)
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContex t.search(PartialCompositeDirContext.java:339)
    at javax.naming.directory.InitialDirContext.search(In itialDirContext.java:267)
    at org.springframework.ldap.pool.validation.DefaultDi rContextValidator.validateDirContext(DefaultDirCon textValidator.java:165)
    at org.springframework.ldap.pool.factory.DirContextPo olableObjectFactory.validateObject(DirContextPoola bleObjectFactory.java:169)
    at org.apache.commons.pool.impl.GenericKeyedObjectPoo l.evict(GenericKeyedObjectPool.java:1897)
    at org.apache.commons.pool.impl.GenericKeyedObjectPoo l$Evictor.run(GenericKeyedObjectPool.java:2272)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream. java:189)
    at java.net.SocketInputStream.read(SocketInputStream. java:121)
    at java.io.BufferedInputStream.fill(BufferedInputStre am.java:235)
    at java.io.BufferedInputStream.read1(BufferedInputStr eam.java:275)
    at java.io.BufferedInputStream.read(BufferedInputStre am.java:334)
    at com.sun.jndi.ldap.Connection.run(Connection.java:8 49)
    at java.lang.Thread.run(Thread.java:724)   

Tomcat exception:

Dec 14, 2013 1:05:57 PM org.apache.tomcat.util.net.JIoEndpoint$Acceptor run
SEVERE: Socket accept failed
java.net.SocketException: Too many open files
    at java.net.PlainSocketImpl.socketAccept(Native Method)
    at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398)
    at java.net.ServerSocket.implAccept(ServerSocket.java:530)
    at java.net.ServerSocket.accept(ServerSocket.java:498)
    at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:60)
    at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:216)
    at java.lang.Thread.run(Thread.java:724)

Here is the ldap connection pool configuration:

<bean id="sdLdapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    <property name="contextSource" ref="sdContextSource" />
    <!-- <property name="contextSource" ref="sdContextSourceTarget" /> -->
</bean>

<bean id="sdContextSource"
    class="org.springframework.ldap.transaction.compensating.manager.TransactionAwareContextSourceProxy">
    <constructor-arg ref="sdPooledContextSource" />
</bean>

<bean id="sdPooledContextSource"
    class="org.springframework.ldap.pool.factory.MutablePoolingContextSource">
    <property name="contextSource" ref="sdContextSourceTarget" />
    <property name="dirContextValidator" ref="dirContextValidator" />
    <property name="testOnBorrow" value="false" />
    <property name="testWhileIdle" value="true" />
    <property name="minIdle" value="3" />
    <property name="maxIdle" value="8" />
    <property name="maxActive" value="100" />
    <property name="maxTotal" value="100" />
    <property name="maxWait" value="100" />
    <property name="timeBetweenEvictionRunsMillis" value="60000" />
    <property name="minEvictableIdleTimeMillis" value="180000" />
</bean>

<bean id="sdContextSourceTarget" class="org.springframework.ldap.core.support.LdapContextSource">
    <property name="url" value="${sd.url}" />
    <property name="userDn" value="${sd.account}" />
    <property name="password" value="${sd.pwd}" />
    <property name="pooled" value="false" />
</bean>

<bean id="dirContextValidator"
    class="org.springframework.ldap.pool.validation.DefaultDirContextValidator">
</bean>
0

There are 0 answers