Bug 54235 - tomcat jdbc pool stackoverflow error used with spring
tomcat jdbc pool stackoverflow error used with spring
Status: RESOLVED FIXED
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool
unspecified
PC All
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2012-12-03 11:29 UTC by yanky
Modified: 2014-08-07 21:09 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yanky 2012-12-03 11:29:47 UTC
I'm evaluating jdbc pool after reading some blogs on  tomcatexpert.com. But when I try to switch to jdbc pool from dbcp, I'm  getting stackoverflow error like this:

Caused by: java.lang.StackOverflowError
    at java.util.concurrent.AbstractExecutorService.<init>(AbstractExecutorService.java:71)
    at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1270)
    at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1163)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:117)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:86)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDataSource(PooledConnection.java:224)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:180)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:631)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:485)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:86)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDataSource(PooledConnection.java:224)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:180)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:631)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:485)
    at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:143)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
    at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:86)
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDataSource(PooledConnection.java:224)

and I noticed that someone had the same issue before but not answered:
http://mail-archives.apache.org/mod_mbox/tomcat-users/201107.mbox/%3C32046311.post@talk.nabble.com%3E

my web app is a typical springmvc+hibernate application, and here is my applicationcontext datasource part:

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="${telregistry.jdbc.driverClassName}" />
<property name="url" value="${telregistry.jdbc.url}"/>
<property name="username" value="${telregistry.jdbc.username}"/>
<property name="password" value="${telregistry.jdbc.password}"/>
<property name="initialSize" value="5"/>
<property name="initSQL" value="SELECT 1"/>
<property name="minIdle" value="5"/>
<property name="maxIdle" value="50"/>
<property name="maxActive" value="100"/>
<property name="maxWait" value="6000"/>
<property name="validationInterval" value="1800000"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>

my system:
win7 32bit
jdk1.7.0_9(also test on jdk1.6.0_25)
mysql 5.5(also test oracle11g)
spring 3.1.0
jdbc pool(tomcat-jdbc-7.0.30.jar from official maven repo)

And by tomcat container resource configuration, I find a workaround to make jdbc pool work with spring: 
1. add a Resource section in tomcat server.xml to make a global naming resource
2. add a resource-ref section in WEB-INF/web.xml to reference container resource
3. add a bean section to spring applicationContext.xml to reference container resouce by spring provided JndiObjectFacetoryBean
Comment 1 Konstantin Kolinko 2012-12-04 20:32:24 UTC
1. The call to ConnectionPool.borrowConnection( ) is caused by setting 

  <property name="initialSize" value="5"/>

which causes ConnectionPool.init() to create 5 connections.


2. The call to PooledConnection.connectUsingDataSource() is seriously wrong.
It should have called PooledConnection.connectUsingDriver() instead.

This can happen only if poolProperties.getDataSource() is not null.

I do not see how this could have happened. Did Spring injected a recursive reference by calling DataSource.setDataSource()?


3. When you define the pool via <Resource>, it is created using org.apache.tomcat.jdbc.pool.DataSourceFactory. The factory calls dataSource.createPool().

So it might be better to add init-method="createPool".
Comment 2 Arjen van der Meijden 2013-05-01 13:25:46 UTC
Do you have autowire in Spring enabled? If so, it'll inject a 'dataSource'-object in the setDataSource-property of your DataSource-instance...

Its a bit weird that the object has a setDataSource-method at all, but you can fairly easily fix it by setting autowire="no" on the particular pool, like so:

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close" autowire="no">
Comment 3 Filip Hanik 2014-08-07 21:09:25 UTC
This can only happen if you inject your datasource (the actual pool).
So this must be a misconfiguration on the users part.

Pool now prevents it through r1616595