Grails, MySQL and java.io.EOFException: Can not read response from server.

with No Comments

After migration to new PROD server start getting error from some inactivity period

2012-04-11 14:27:29,415 [TP-Processor3] ERROR (org.hibernate.util.JDBCExceptionReporter) – Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.io.EOFException
MESSAGE: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
STACKTRACE:
java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
      at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1997)
      at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2411)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2916)
      at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
      at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
      at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
      at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
      at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1448)
      at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
      at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
      at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
      at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
      at org.hibernate.loader.Loader.doQuery(Loader.java:697)

 

Possible Solution

On previous server I’ve already had Broken Pipe error with MySQL and successfully solved it with http://sacharya.com/grails-dbcp-stale-connections/
But on new server (Red Hat Enterprise Linux) it failed.

After digging a lot I found http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai and some other topics which helped.

Resulted config which fix problem is following:

  • On server in /etc/hosts.allow added ‘mysqld : ALL : ACCEPT’
  • On server in /etc/my.cf added ‘port=3306′
  • In DataSource.groovy added properties
  • In DataSource.groovy changed datadase URL to have IP (127.0.0.1) instead of localhost: ‘jdbc:mysql://127.0.0.1:3306/db_name’

That’s all!

Leave a Reply