The connection is already closed

I use Grails 2.5.3 and Tomcat7, and after 8 hours of application deployment, our logs begin to explode with connection problems already closed. A good guess is that MySql kills the connection after a default timeout of 8 hours.

According to the docs, my pool seems to be configured correctly to keep open connections open, but it doesn't seem to be that way.

What could be wrong in setting up a connection pool?

dataSource {
  pooled = true
  url = 'jdbc:mysql://******.**********.us-east-1.rds.amazonaws.com/*****'
  driverClassName = 'com.mysql.jdbc.Driver'
  username = '********'
  password = '******************'
  dialect = org.hibernate.dialect.MySQL5InnoDBDialect
  loggingSql = false
  properties {
    jmxEnabled = true
    initialSize = 5
    timeBetweenEvictionRunsMillis = 10000
    minEvictableIdleTimeMillis = 60000
    validationQuery = "SELECT 1"
    initSQL = "SELECT 1"
    validationQueryTimeout = 10
    testOnBorrow = true
    testWhileIdle = true
    testOnReturn = true
    testOnConnect = true
    removeAbandonedTimeout = 300
    maxActive=100 
    maxIdle=10 
    minIdle=1
    maxWait=30000
    maxAge=900000
    removeAbandoned="true"
    jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.StatementCache;"

  }
}

hibernate {
  cache.use_second_level_cache=true
  cache.use_query_cache=true
  cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
}

Also , I confirmed that the dataSource is an instance ( org.apache.tomcat.jdbc.pool.DataSource) at runtime

1 ( ) , , , ! http , factory, , http - . http 8 , , . , .

2 () , , . removeAbedoned removeAbandonedTimeout . , , , , . , . 4 - .

+4
3

URL :

url = "jdbc:mysql://localhost/db?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"

, .

+2

. . :

  • - , , Java - "" . :

    con = ( ); (330 ); con.close();

    1. , tomcat 300 .

    2. , , ( , ) .

    3. 330 , , . , , .

    4. ,

    5. . .

: logAbandoned = "true", , .

+1

(. 2 )

Removing removeAbandoned and removeAbandonedTimeout resolved all our problems. Someone might want to give a more detailed answer about why this happened, because we are not entirely sure.

0
source

All Articles