JavaのWEBアプリ(servlet/jsp)をherokuにデプロイしたのですが、1分程触らずに置いて、その後ページ移動をするとCommunications link failureのエラーが発生します。このエラーを解決したく思います。
DB(Mysql)側の問題だと思い、herokuのMysqlのタイムアウト変更を試みましたが変更が上手く行きません。
herokuのデータベースでの設定変更の解決策を教えて頂きたく、また根本の原因がそもそも違うなどあればご教示頂ければ幸いです。
○localhostで作成したWEBアプリのデータをdump.sqlを用いてherokuとつなげました。
「mysql -h (ドメイン) -u (ユーザ名) -p」でログイン後
↓
「mysql> set global net_write_timeout=28800;」エラー
発生している問題・エラーメッセージ(WEBページ上)
HTTP Status 500 - org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection 〜〜〜〜〜〜中略〜〜〜〜〜〜〜〜〜〜 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 77,343 milliseconds ago. The last packet sent successfully to the server was 15 milliseconds ago. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) java.lang.reflect.Constructor.newInstance(Constructor.java:423) com.mysql.jdbc.Util.handleNewInstance(Util.java:425) com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990) com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3559) com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3459) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3900) com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2480) com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4811) org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.poll(DriverManagerConnectionProviderImpl.java:324) org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:189) org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35) org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106) org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136) org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47) org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146) org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172) org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148) org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1985) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1915) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893) org.hibernate.loader.Loader.doQuery(Loader.java:938) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) org.hibernate.loader.Loader.doList(Loader.java:2692) org.hibernate.loader.Loader.doList(Loader.java:2675) org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507) org.hibernate.loader.Loader.list(Loader.java:2502) org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:392) org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490) org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445) org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) org.hibernate.query.Query.getResultList(Query.java:146) controllers.comics.ComicIndexServlet.doGet(ComicIndexServlet.java:46) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) filters.LoginFilter.doFilter(LoginFilter.java:64) filters.EncodingFilter.doFilter(EncodingFilter.java:40) root cause java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3011) com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3469) com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3459) com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3900) com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527) com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2480) com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4811) org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.poll(DriverManagerConnectionProviderImpl.java:324) org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:189) org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35) org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106) org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136) org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:47) org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:146) org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:172) org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:148) org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1985) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1915) org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893) org.hibernate.loader.Loader.doQuery(Loader.java:938) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) org.hibernate.loader.Loader.doList(Loader.java:2692) org.hibernate.loader.Loader.doList(Loader.java:2675) org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507) org.hibernate.loader.Loader.list(Loader.java:2502) org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:502) org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:392) org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) org.hibernate.internal.SessionImpl.list(SessionImpl.java:1490) org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1445) org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) org.hibernate.query.Query.getResultList(Query.java:146) controllers.comics.ComicIndexServlet.doGet(ComicIndexServlet.java:46) javax.servlet.http.HttpServlet.service(HttpServlet.java:622) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) filters.LoginFilter.doFilter(LoginFilter.java:64) filters.EncodingFilter.doFilter(EncodingFilter.java:40) note The full stack trace of the root cause is available in the Apache Tomcat/8.0.50 logs.
該当のソースコード
SQL
1 mysql> set global net_write_timeout=28800;
試したこと
「$ mysql -h (herokuドメイン) -u (herokuユーザ名) -p」 ログイン
↓
「mysql> set global net_write_timeout=28800;」 上記画像のエラー
↓ユーザーにsuperの権限が必要だと思い下記実行
「mysql> UPDATE mysql.user SET Super_priv='Y' WHERE user='(herokuユーザー名)';」 上記画像のエラー
※mysql -u root -p でのrootのログインでは上記の数値変更や権限付与は問題なくできました。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
--開発環境--
言語:Java、SQL
DB:MySQL
フレームワーク:Hibernate
AP:Tomcat
開発環境:Eclipse