sfgroups
sfgroups

Reputation: 19099

Grails mysql connection time out in production mode

I have deployed a grails application in tomcat 7. Database connection works fine during normal time, but in the night the connection is getting closed. Next day I have to restart the tomcat to make it work.

Here is my connection string in the config file.

production {
        dataSource {
            dbCreate = "update"
            pooled = true
                        logSql = true
                        driverClassName =  "com.mysql.jdbc.Driver"
                        dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
                        url =
            properties {
               maxActive = -1
               minEvictableIdleTimeMillis=1800000
               timeBetweenEvictionRunsMillis=1800000
               numTestsPerEvictionRun=3
               testOnBorrow=true
               testWhileIdle=true
               testOnReturn=true
               validationQuery="SELECT 1"
            }
        }

error log:

Broken pipe. Stacktrace follows:
java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
        at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2728)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2678)
        at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)

also I see this message in the log file.

appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

How can I fix the connection time out issue.

Upvotes: 0

Views: 1022

Answers (1)

Igor Artamonov
Igor Artamonov

Reputation: 35961

You have to add autoReconnect=true to the connection url, it will help with such conection issues.

Like:

production {
  dataSource {
    ...
    url = 'jdbc:mysql://localhost/dbname?autoReconnect=true'
    ...
  }
}

Upvotes: 2

Related Questions