-1

“Communications link failure” error on MySQL using JDBC after the program has run for 38 hrs. Another program on the same machine hitting the same server (also java) continues to run. Both are using the exact same java code to access the server, as do the java programs running on 4 other machines at the same time. I get this error randomly on different machines, after a program has been running successfully (reads/inserts/updates to the database) for quite a while. The error includes the first line above the stack trace:

The last packet successfully received from the server was n milliseconds ago. where n has varied between 0 and 25.

I might suspect that the server has run out connections to hand out, but I get a totally different error when that happens (I encountered it and updated my server to increase max connections, which eliminated that error). I get the error whether I use c3p0 to pool connections, or not.

Please read before flagging as a duplicate. The connect string and database are fine, as it worked for 38 hours (and continues to work in other processes on the same machine and different machines accessing the same MySQL server) using exactly the same java code. This is a transient/random error. If I simply restart the program, it continues successfully. I would say it's OS related, except that it occurs on both Windows and Mac OS X. Which leads me to believe it's likely something going on in the java VM.

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
  • 1
    Possible duplicate of [com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure](http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai) – Thilina Samiddhi Apr 18 '17 at 03:03
  • 1
    Please read before flagging as duplicate. The connect string and database are fine, as it worked for 38 hours (and continues to work in other processes on the same machine and different machines) using exactly the same java code. This is a transient/random error. If I simply restart the program, it continues successfully. I would say it's OS related, except that it occurs on both Windows and Mac OS X. Which leads me to believe it's likely something going on in the java VM. – M.S.Elliott Apr 18 '17 at 14:51

1 Answers1

0

Considering the point that you mention, that it is running fine until 38 hours and then you get the following issue - It only leads to one logical point:

If your connection is IDLE for a considerably longer duration. This idle connection would evaluate connection.isClosed(); to TRUE, and when we try to execute the above statement it will then fire the following exception.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

How to remediate this issue?

Switch to DB Connection Pooling. Hope this helps!

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
  • Sorry, should have mentioned that the app is using c3p0 for connection pooling. So already doing that. I should also note that I haven't see this error since the last JVM update - so maybe something was fixed in that. But hard to say since it's always been a sporadic problem. – M.S.Elliott May 11 '17 at 16:22
  • You're getting that error even after implementing Connection pooling, that's strange!!! – N00b Pr0grammer May 11 '17 at 16:43