I noticed an exception like this one in one of our applications’ log and was investigating it. Here’s it:
[20:26:51] WARN [org.hibernate.util.JDBCExceptionReporter] – SQL Error: 0, SQLState: 08S01
[20:26:51] ERROR [org.hibernate.util.JDBCExceptionReporter] – Communications link failure
Last packet sent to the server was 96429 ms ago.
. . .
org.springframework.dao.DataAccessResourceFailureException: Cannot open connection; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection
Seems there was a stale connection at that point of time in Hibernate‘s C3P0 connection pool. MySQL might have timed out the connection, but C3P0 wasn’t probably configured with an appropriate value for idle_test_period and timeout properties, and hence the said connection might have stayed on without getting validated/removed. (The property idle_test_period defines the interval to test unchecked-out connections while timeout is the time unused connections can live in the pool.
If this is a one-off case, there’s no need to worry; just observe this failure over a period of time. If this happens frequently, we may need to double-check the values for above properties.