Bug 248 : When make Paging query the connection is not closed & How to configure the JNDI of Tomcat?
Priority 
High
Reported Version 
 
Logged By 
zhoupeng
Status 
Fixed
Fixed Version 
2.5.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
16/03/2010
Updated 
16/03/2010
Type 
Bug
 
Attachments 
No attachments

Exception Info:

2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[1] size[1] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[2] size[2] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[3] size[3] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[4] size[4] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[5] size[5] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[6] size[6] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[7] size[7] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[8] size[8] max[10]
select count(*) from WF_PROCESSDEFINITION f
3
2010-3-16 21:16:32 com.avaje.ebean.server.lib.sql.DataSourcePool createConnection
��������?��: DataSourcePool [ora] grow pool; busy[9] size[9] max[10]
select count(*) from WF_PROCESSDEFINITION f
��������?��: Busy Connections:

Exception in thread "main" javax.persistence.PersistenceException: javax.persistence.PersistenceException: java.sql.SQLException: Unsuccessfully waited for a connection to be returned. No connections are free. You need to Increase the max connections or look for a connection pool leak.
at com.avaje.ebean.server.query.LimitOffsetPagingQuery.getTotalRowCount(LimitOffsetPagingQuery.java:151)
at com.ninemax.animation.persistence.template.EbeanSupport.main(EbeanSupport.java:78)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)
Caused by: javax.persistence.PersistenceException: java.sql.SQLException: Unsuccessfully waited for a connection to be returned. No connections are free. You need to Increase the max connections or look for a connection pool leak.
at com.avaje.ebean.server.transaction.TransactionManager.createTransaction(TransactionManager.java:356)
at com.avaje.ebean.server.core.DefaultServer.createTransaction(DefaultServer.java:635)
at com.avaje.ebean.server.core.DefaultServer.findFutureRowCount(DefaultServer.java:1246)
at com.avaje.ebean.server.query.LimitOffsetPagingQuery.getFutureRowCount(LimitOffsetPagingQuery.java:80)
at com.avaje.ebean.server.query.LimitOffsetPagingQuery.getTotalRowCount(LimitOffsetPagingQuery.java:149)
... 6 more
Caused by: java.sql.SQLException: Unsuccessfully waited for a connection to be returned. No connections are free. You need to Increase the max connections or look for a connection pool leak.
at com.avaje.ebean.server.lib.sql.DataSourcePool._getPooledConnection(DataSourcePool.java:818)
at com.avaje.ebean.server.lib.sql.DataSourcePool.getPooledConnection(DataSourcePool.java:757)
at com.avaje.ebean.server.lib.sql.DataSourcePool.getConnection(DataSourcePool.java:745)
at com.avaje.ebean.server.transaction.TransactionManager.createTransaction(TransactionManager.java:331)
... 10 more


Ebean.properties:
datasource.ora.username= animation
datasource.ora.password= animation
datasource.ora.databaseUrl=jdbc:oracle:thin:@127.0.0.1:1521:LOCALDB
datasource.ora.databaseDriver=oracle.jdbc.driver.OracleDriver
datasource.ora.minConnections=1
datasource.ora.maxConnections=10
#datasource.ora.heartbeatsql=select count(*) from dual
datasource.ora.isolationlevel=read_committed
#######################zhoupeng
datasource.ora.maxInactiveTimeSecs=-1
datasource.ora.leakTimeMinutes=-1
datasource.ora.waitTimeoutMillis=1000
#datasource.ora.captureStackTrace=true
#datasource.ora.autoCommit=true

 
zhoupeng 16 Mar 14:42
Test Function

public static void main(String args []){

}

zhoupeng 16 Mar 14:44
Test Function

public static void main(String args []){

for(int i=0;i<15;i++){
PagingList list = Ebean.find(Order.class).findPagingList(10);
}
}

Rob 17 Mar 03:33
I didn't reproduce

Sorry, didn't reproduce in H2 or Oracle.

I stepped through the code ... and it doesn't create a transaction / get a connection.

package com.avaje.tests.query;

import junit.framework.TestCase;

import com.avaje.ebean.Ebean;
import com.avaje.tests.model.basic.Customer;
import com.avaje.tests.model.basic.ResetBasicData;

public class TestPagingListLoop extends TestCase {

    public void test() {
        
        ResetBasicData.reset();
        
        for (int i = 0; i < 50; i++) {
            Ebean.find(Customer.class).findPagingList(10);
        }
        
    }
    
}

Note that in the log you will see entries like:

17/03/2010 03:29:02 com.avaje.ebeaninternal.server.lib.sql.DataSourcePool createConnection
INFO: DataSourcePool [ora] grow pool; busy[1] size[1] max[25]

Whenever the connection pool grows ... so you should be seeing ten of those.
Also you should be able to turn on the capturestacktrace feature.

datasource.ora.capturestacktrace=true

Rob 17 Mar 09:38
Please provide a test case

... that reproduces the problem.

Thanks, Rob.

Rob 17 Mar 20:00
Ok, I figured out how to reproduce ...
for (int i = 0; i < 50; i++) {
    PagingList<Customer> pagingList = Ebean.find(Customer.class).findPagingList(10);
    pagingList.getFutureRowCount();    
}

The problem is in the FutureRowCount mechanism.

Rob 17 Mar 21:49
Fixed in HEAD

The fix was around adding a SpiEbeanServer.findRowCountWithCopy(...) method.

The issue was around the timing of the query copy() ... the original query is copied before being modified to execute findRowCount.

Fixed in HEAD.

woResponse

Upload a file