Grails 2.3.4 Pool empty. Unable to fetch a connection in 30 seconds

grails, grails-orm, tomcat

Solution

Grails 2.3.x replaced Commons DBCP with Tomcat JDBC, that may be the reason for the difference in your application. You can check for differences in the pool configuration.

Problem

We have grails application ruining in tomcat 7.0.30. Grails version was 2.2.4, and it was running very stable during last year. I Tried to switch grails version to 2.3.4, On test environment it was acting normal(no any issues). But when I put it on production after 20 minutes I start getting following exceptions ``` [ajp-bio-9009-exec-430] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100; idle:0; lastwait:30000].. Stacktrace follows: org.apache.tomcat.jdbc.pool.PoolExhaustedException: [ajp-bio-9009-exec-430] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100; idle:0; lastwait:30000]. at grails.gorm.DetachedCriteria$_count_closure4.doCall(DetachedCriteria.groovy:686) at grails.gorm.DetachedCriteria$_withPopulatedQuery_closure10.doCall(DetachedCriteria.groovy:931) at org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure20.doCall(GormStaticApi.groovy:680) at org.grails.datastore.mapping.core.DatastoreUtils.execute(DatastoreUtils.java:302) at org.grails.datastore.gorm.AbstractDatastoreApi.execute(AbstractDatastoreApi.groovy:37) at org.grails.datastore.gorm.GormStaticApi.withDatastoreSession(GormStaticApi.groovy:679) at grails.gorm.DetachedCriteria.withPopulatedQuery(DetachedCriteria.groovy:913) at grails.gorm.DetachedCriteria.count(DetachedCriteria.groovy:684) at grails.gorm.DetachedCriteria.count(DetachedCriteria.groovy:683) at com.webbfontaine.wftaglib.BeanDataLoadController.doLoadData(BeanDataLoadController.groovy:30) at com.webbfontaine.wftaglib.BeanDataLoadController$_closure1.doCall(BeanDataLoadController.groovy:14) at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195) at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) at org.josso.tc70.agent.SSOAgentValve.invoke(SSOAgentValve.java:684) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) ``` In our application all queries to DB are done via Grails GORM, we do not use any SQL or HQL query. My guess is that something is wrong in grails 2.3.4 itself (some connections are not closed / returned to pool correctly). Am i missing something or its grails issue ? Any ideas ?

Original source