1
votes

I published a backend project in google App Engine since 1 year, and all seems good, 1 week ago this Exception started to throw in logs sometimes (not always) during executing a JPA select query in Cloud SQL and sometimes the query is just returning the result successfully:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 309,979 milliseconds ago. The last packet sent successfully to the server was 309,981 milliseconds ago.
Error Code: 0
Call: SELECT ID, created_time, CURRENCY, IP, NAME FROM country_table Query: ReadAllQuery(name="Country.findAll" referenceClass=Country sql="SELECT ID, created_time, CURRENCY, IP, NAME FROM country_table")

and sometimes this exception is stopping some queries to be executed:

The last packet successfully received from the server was 219,443 milliseconds ago. The last packet sent successfully to the server was 219,446 milliseconds ago.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:44) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117) at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3851) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2739) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2149) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2313) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1007) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:642) at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558) at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2002) at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570) at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:250)

1
I've applied almost most of the solutions like adding parameters to the JPA connection string like autoReconnect, interactiveClient, maxReconnects, failOverReadOnly, and however the error still happening, and with every single request coming to me Im getting a new entity manager and close it right afterTamer Saleh

1 Answers

0
votes

This is because MySQL closed the connection.

Probably JPA will automatically reconnect to the database. If the transaction result is correct, you can ignore this message.

Or you can extend the timer until connection close with interactive_timeout and wait_timeout on developer console. This can reduce the message.