Reputation: 4998
i just got deploying a very simple grails app in heroku using cleardb addon, everything is fine until past some minutes and when i try to get view that has access to database i get and error message.
Here i paste a snippet from heroku logs
2014-06-04T20:12:17.511251+00:00 app[web.1]: 2014-06-04 20:12:17,511 [http-nio-38536-exec-1] ERROR util.JDBCExceptionReporter - No operations allowed after
connection closed.
2014-06-04T20:12:17.515181+00:00 app[web.1]: 2014-06-04 20:12:17,514 [http-nio-38536-exec-1] ERROR errors.GrailsExceptionResolver - EOFException occurred when processing request: [GET] /user
2014-06-04T20:12:17.515187+00:00 app[web.1]: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.. Stacktrace follows:
2014-06-04T20:12:17.515190+00:00 app[web.1]: at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3166)
2014-06-04T20:12:17.515188+00:00 app[web.1]: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
And here is my datasource production section
production {
dataSource {
dbCreate = "update"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
uri = new URI(System.env.CLEARDB_DATABASE_URL?:"//bb2c98a68a13fe:[email protected]/heroku_b28cc03a245469f?reconnect=true")
url = "jdbc:mysql://"+uri.host+uri.path
username = uri.userInfo.split(":")[0]
password = uri.userInfo.split(":")[1]
}
}
The log tell me about connection closed. i do not know what to do from here, i hope you can help me, thanks for your time
Upvotes: 2
Views: 1712
Reputation: 4998
I finally got a solution to this problem, thanks for the help from heroku support team and cleardb support team, the solution was to add properties to datasource into production environment, the final code in datasource.groovy
production {
dataSource {
dbCreate = "update"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
uri = new URI(System.env.CLEARDB_DATABASE_URL?:"//bb2c98a68a13fe:[email protected]/heroku_b28cc03a245469f?reconnect=true")
url = "jdbc:mysql://"+uri.host+uri.path
username = uri.userInfo.split(":")[0]
password = uri.userInfo.split(":")[1]
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
jmxEnabled = true
initialSize = 5
maxActive = 50
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
this are the default values just do not delete it as i did it.
the reason why is this necessary is in cleardb team support answer, i paste next
6/05/2014 03:07PM wrote
Hello,
My suspicion - without troubleshooting further, just a first pass - is that your app is not managing connections properly. Your current database service tier allows a maximum of 4 simultaneous connections to the db. It is likely that your application is trying to open more connections than are allowed.
If you are using connection pooling, you must make sure that your pool is set to no larger than 4 total (and that's across all dynos if you have more than 1).
Heroku's networking times out idle connections at 60 seconds, so your database connector must be set either to have an idle timeout of no more than 60 seconds, or you must have a keep-alive interval of less than 60 (which sends a trivial query such as "SELECT 1" to keep the connection active).
We do not support grails directly, so I unfortunately can't give you specific directions of how to do that within this framework.
I hope this is helpful.
Mike ClearDB Support Team
I hope it help to someone
Upvotes: 4