Bug #61747 Communications link failure with mysql from JDBC
Submitted: 5 Jul 2011 8:35 Modified: 26 Apr 2013 7:01
Reporter: terry whelan Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.0 OS:Solaris (solaris10 update 8)
Assigned to: Alexander Soklakov CPU Architecture:Any

[5 Jul 2011 8:35] terry whelan
Description:
I am running mysql queries/updates via JDBC, my java application has began to hang recently and the log file has an error from mysql (see below)

The Java application would carry out SELECT and UPDATE statements via jdbc on our mysql datbase (approx 80 tables)

We are running mysql 5.0 on top of solaris 10 update8 on x86 platform.

--------------------------------------------------------------------------------
SelectStr: show tables
Error while executing SQL transaction: No operations allowed after connection closed.Connection was implicitly closed due to underlying exception/error:

** BEGIN NESTED EXCEPTION **

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
MESSAGE: Communications link failure

Last packet sent to the server was 1 ms ago.

STACKTRACE:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 1 ms ago.
    at sun.reflect.GeneratedConstructorAccessor13.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2873)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2763)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3299)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1837)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1961)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2537)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2466)
    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383)
    at com.sun.electron.utils.DBConnection.doSelect(DBConnection.java:402)
    at com.sun.electron.utils.DBConnection.doSelect(DBConnection.java:382)
    at com.sun.electron.utils.DBConnection.doSelect(DBConnection.java:370)
    at com.sun.electron.utils.DBConnection.isAliveAtDBLevel(DBConnection.java:196)
    at com.sun.electron.utils.DBConnection.isAlive(DBConnection.java:185)
    at com.sun.electron.utils.DBConnection.getConnectionState(DBConnection.java:207)
    at com.sun.electron.utils.DBConnection.printStates(DBConnection.java:224)
    at com.sun.electron.utils.RweServer.main(RweServer.java:101)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2332)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2774)
    ... 15 more

** END NESTED EXCEPTION ** 

How to repeat:
Unfortunately this is a random issue and I do not know what set of conditioons bring it about. The Java application can have quite a heavy load of UPDATE/SELECT going on and I do mnot know what trioggers the hang

All I have is the error from the toomcat logs above (did not get any info from mysql logs)

I am hoping that the error stack trace will make this easy to identify (this issue look similar to http://bugs.mysql.com/bug.php?id=48346 

I'd like to know what checks I can put in place to catch more debugging information if/when this occurs again

Also what data from my.cnf do you require?
[5 Jul 2011 9:40] Tonci Grgin
Terry, you've given me nothing to work with... My best guess is that you're closing the connection from the different thread than the one issuing "SHOW TABLES".

Further more, I do not know which version of c/J you are using, nor do I see a repeatable test case (with connection string and all) attached, much like in report you're referring to.
[13 Jul 2011 6:44] terry whelan
This issue is random and I do not have a reproducible test case

However - I would like help to diagnose *where* the error is .. and how I can ensure I have an appropriate logging setup in case of future occurance

Is this an error in Java or Mysql i.e. where exactly in the stack does the error come from???

If this is a mysql error .. then what logfile would be most appropriate to query?

How can I maximise MYSQL logging to ensure I get as much information from log files if this occurs again?
[13 Jul 2011 6:51] Tonci Grgin
Terry, again, all I can do is guess. 1st guess was you closed the connection from one thread while still working with it in another. Thread-safe does not mean "sharable across threads" nor does it shield from such coding practices. 2nd guess would be MySQL server restarted. You can check for 1st in your code (sharing connection between threads) and for 2nd in \\DATADIR\your_server_name.err file.
It could also be a fail-over problem, maybe even something caused by network hardware/software failure and so on...

Side-note: If I can not reliable reproduce the problem I have nothing to "fix", agree?
[13 Aug 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".
[26 Apr 2013 7:01] Alexander Soklakov
There is no feedback since Jul 2011 and I close this report as "Can't repeat".
Please, feel free to reopen it if the problem still exists and you can provide more info to analyze.