users@glassfish.java.net

Communications Exception after wait_timeout expires in MySQL 5

From: <glassfish_at_javadesktop.org>
Date: Wed, 04 Mar 2009 13:00:44 PST

When wait_timeout expires my application fails to reconnect to the database and throws the exception below (I'm using v2.1). This wasn't a problem until we moved from MySQL 4.1.7 with Connector/J 3.1 to MySQL 5.0 and Connector/J 5.1. Setting autoReconnect=true doesn't have any impact, nor does AutoReconnectForPools=true or AutoReconnectForConnectionPools=true (though if anyone could explain the differences between these variables, I would be delighted.) Connection validation is required (I'm using the table method), though it is not set to close all connections on failure. My idle timeout is at 300 seconds and my wait_timeout is the default 8 hours. I haven't seen any other suggestions for fixing this problem, does anyone know how to get around it?

MySQL documentation seems to suggest that autoReconnect is, or soon will be, deprecated, and that all applications should deal with this issue by handling the CommunicationsException. It seems to me that my container should be doing this, right?


[#|2009-03-04T14:02:43.789-0600|WARNING|sun-appserver2.1|oracle.toplink.essentials.session.file:/opt/glassfish/domains/internal/applications/j2ee-modules/myapp/-NewtPU|_ThreadID=14;_ThreadName=http
SSLWorkerThread-8181-0;_RequestID=31c89a9d-59ab-4668-8553-bdcd53912e5a;|
Local Exception Stack:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was85533 milliseconds ago.The last packet sent successfully to the server was 85533 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.
Error Code: 0
Call: SELECT AccountID, DateDeactivated, DateCreated, AcctMgr, RefContactID FROM Accounts WHERE (AccountID = ?)
        bind => [1000213]
Query: ReadObjectQuery(com.myco.myapp.Account)
        at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
        at
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was85533 milliseconds ago.The last packet sent successfully to the server was 85533 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.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
Caused by: java.net.SocketException: Broken pipe
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
 ...
[Message sent by forum member 'loren_' (loren_)]

http://forums.java.net/jive/thread.jspa?messageID=335146