7

Occasionally, my Java/Tomcat6/Debian Squeeze application can't talk to the MySql server. The Tomcat application is on a front-end server and MySql is on a separate, MySql-only box. A typical error is:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was56588 milliseconds ago.

The last packet sent successfully to the server was 56588 milliseconds ago, which 
is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the
server configured values for client timeouts, or using the Connector/J connection property
 'autoReconnect=true' to avoid this problem.

The timeout time given is only 60 seconds, which seems very short. If it was an hour or more, I would simply setup a background task to ping the DB-server every few minutes. I've added the autoReconnect parameter to the opening URL, with no obvious impact.

Any idea as to what the problem is here? Thanks Pat

ScottJShea
  • 7,041
  • 11
  • 44
  • 67
fishtoprecords
  • 2,394
  • 7
  • 27
  • 38

2 Answers2

0

You should code for network glitches and deal with auto-reconnect yourself.

auto-reconnect is deliberately OFF because of several 'application' bugs that can silently happen when the connection goes away and comes back in a different state.

Anyway, a comment shows that this is somewhat a Duplicate question.

Rick James
  • 135,179
  • 13
  • 127
  • 222
0

Configure c3p0 properties for overcome this issue. Use properties like,

hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.min_size=0
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=500
hibernate.c3p0.max_statements=50
hibernate.c3p0.idle_test_period=3000
hibernate.c3p0.testConnectionOnCheckout=true
hibernate.c3p0.acquire_increment=1

with JDBC connection URL url=jdbc:mysql://host/databasename?autoReconnect=true

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
  • `autoReconnect` is deprecated and not recommended (see the property description in the [Connector/J reference](https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html#connector-j-reference-set-config) or the note at the end of [section 15.4](https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-usagenotes-troubleshooting.html#qandaitem-15-1-4) of the troubleshooting chapter) since at least [2004](https://bugs.mysql.com/bug.php?id=5020). – vilpan Jun 24 '17 at 11:33