【问题标题】:connection closed error in heroku cleardb addonheroku cleardb 插件中的连接关闭错误
【发布时间】:2014-06-06 02:00:52
【问题描述】:

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

这里我从heroku日志中粘贴了一个sn-p

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]
    }
}

日志告诉我连接已关闭。我不知道从这里做什么,希望你能帮助我,谢谢你的时间

【问题讨论】:

    标签: grails heroku


    【解决方案1】:

    我终于找到了解决这个问题的方法,感谢heroku支持团队和cleardb支持团队的帮助,解决方法是在生产环境中添加datasource的属性,最终代码在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 写道

    你好,

    我的怀疑 - 没有进一步排除故障,只是第一次通过 - 是 您的应用未正确管理连接。您当前的 数据库服务层最多允许 4 个同时连接 到分贝。您的应用程序可能正在尝试打开更多 超过允许的连接数。

    如果您使用连接池,则必须确保您的池 设置为不超过 4 总数(如果你 有超过 1 个)。

    Heroku 的网络在 60 秒时会超时空闲连接,因此您的 数据库连接器必须设置为空闲超时为 no 超过 60 秒,或者你必须有一个更少的保持活动间隔 大于 60(发送一个简单的查询,例如“SELECT 1”以保持 连接有效)。

    我们不直接支持 grails,所以很遗憾不能给你 在这个框架内如何做到这一点的具体方向。

    我希望这会有所帮助。

    Mike ClearDB 支持团队

    希望对大家有所帮助

    【讨论】:

      猜你喜欢
      • 2017-06-22
      • 1970-01-01
      • 2016-07-05
      • 2018-02-11
      • 1970-01-01
      • 2021-09-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多