Bug #61373 Innacurate error message on java.net.SocketException
Submitted: 1 Jun 2011 12:47 Modified: 29 Apr 2013 12:33
Reporter: Clément MATHIEU Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.16 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any

[1 Jun 2011 12:47] Clément MATHIEU
Description:
A typo in SQLError.createLinkFailureMessageBasedOnHeuristics() leads to an inaccurate error message. 

Indeed I got the following error message while the server timeout is greater than 320380ms:

---
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was320380 milliseconds ago.The last packet sent successfully to the server was 320380 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.
---

This inaccurate error message come from an erroneous test in createLinkFailureMessageBasedOnHeuristics():

---- SQLErrror
   String serverTimeoutSecondsStr = null;
   if (isInteractiveClient) {
      serverTimeoutSecondsStr = conn.getServerVariable("interactive_timeout"); //$NON-NLS-1$
   } else {
      serverTimeoutSecondsStr = conn.getServerVariable("wait_timeout"); //$NON-NLS-1$
   }
  
   if (serverTimeoutSecondsStr != null) {
      try {
         serverTimeoutSeconds = Long.parseLong(serverTimeoutSecondsStr);
      } catch (NumberFormatException nfe) {
         serverTimeoutSeconds = 0;
      }
   }

[....]

   if (serverTimeoutSeconds != 0) {
      if (timeSinceLastPacket > serverTimeoutSeconds) {
---- 

Server timeout is in seconds while elapsed time since last packet is in milliseconds. 

This inaccurate error message is error prone. A quick search in the bug tracker shows that this bug has been reported several times since 2009 but was badly diagnosed leading several "Not a bug" or "Can't repeat". 

How to repeat:
Unplug a RJ45 after some idle time. 

Suggested fix:
- if (timeSinceLastPacket > serverTimeoutSeconds) {
+ if (timeSinceLastPacket > serverTimeoutSeconds * 1000) {
[6 Jun 2011 17:46] Mark Matthews
"timeSinceLastPacket" is in seconds, look further up the screen:

long timeSinceLastPacket = (System.currentTimeMillis() - lastPacketSentTimeMs) / 1000;

(this was fixed way back in 5.1.8)

Are you sure that 5.1.16 is actually in use, or the source that goes with it?
[6 Jul 2011 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[29 Apr 2013 12:33] Alexander Soklakov
Hi Clément,

There is no feedback since Jun 2011, timeSinceLastPacket is in seconds in latest sources, so I close this report as "Not a Bug".
Please, feel free to reopen it if the problem still exists with current driver version.