gpt4 book ai didi

grails - heroku cleardb插件中的连接关闭错误

转载 作者:行者123 更新时间:2023-12-02 13:51:42 25 4
gpt4 key购买 nike

我刚刚使用cleardb addon在heroku中部署了一个非常简单的grails应用程序,直到几分钟后一切都很好,当我尝试获取可以访问数据库的 View 时,我得到了错误消息。

在这里,我从heroku日志中粘贴了一个代码段

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.

这是我的数据源生产部分
production {
dataSource {
dbCreate = "update"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
uri = new URI(System.env.CLEARDB_DATABASE_URL?:"//bb2c98a68a13fe:3a6fd398@us-cdbr-east-06.cleardb.net/heroku_b28cc03a245469f?reconnect=true")
url = "jdbc:mysql://"+uri.host+uri.path
username = uri.userInfo.split(":")[0]
password = uri.userInfo.split(":")[1]
}
}

日志告诉我有关连接已关闭的信息。我不知道该怎么办,希望您能帮助我,谢谢您的宝贵时间

最佳答案

我终于找到了解决这个问题的方法,感谢heroku支持团队和cleardb支持团队的帮助,解决方案是将数据源的属性添加到生产环境中,这是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:3a6fd398@us-cdbr-east-06.cleardb.net/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
}
}
}

这是默认值,只是不要像我那样删除它。

之所以需要这样做,是因为在cleardb团队支持答案中,我粘贴了下一个

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



希望对别人有帮助

关于grails - heroku cleardb插件中的连接关闭错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24046843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com