打印本文 打印本文 关闭窗口 关闭窗口
第一次遇到Mysql的BUG,困扰我好久了。
作者:武汉SEO闵涛  文章来源:敏韬网  点击数863  更新时间:2009/4/22 20:48:27  文章录入:mintao  责任编辑:mintao

第一次遇到Mysql的BUG,困扰我好久了。

采用struts连接缓冲池取得数据库连接,在第一次getConnection()的时候
有时候出现一下错误
java.sql.SQLException: Communication link failure: java.net.SocketException, underlying cause: Software caused connection abort: recv failed

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: Software caused connection abort: recv failed

STACKTRACE:

java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1449)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1826)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1098)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1192)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1153)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2048)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2017)
at com.mysql.jdbc.Connection.execSQL(Connection.java:1998)
at com.mysql.jdbc.Connection.setAutoCommit(Connection.java:516)
at org.apache.struts.legacy.GenericConnection.setAutoCommit(GenericConnection.java:562)
at com.euwsoftware.autocreatewebsite.database.mysql.MysqlDAOFactory.getConnection(MysqlDAOFactory.java:113)

** END NESTED EXCEPTION **



为解决方法(转自 http://bugs.mysql.com/bug.php?id=5020 )
MySQL Bugs: #5020: autoReconnect / autoReconnectForPools broken since 3.0.11 Description:
Our Systems run 24 Hours a Day, but at night nobody connects,
so the Socket Connections time out. At morning the first attempts
to do anything (e.g. login) fail until we are able to close() and
create..() the Connections again.

This did not happen until after 3.0.11

How to repeat:
Connection reconnectableConn = DriverManager.getConnection(
        "jdbc:mysql:///test?autoReconnect=true");

rs = reconnectableConn.createStatement().executeQuery("SELECT 1");
assertTrue  (rs.next());
assertEquals(1, rs.getInt(1));

restartMySQL();  // Actually: NET STOP MySQL; NET START MySQL;

rs = reconnectableConn.createStatement().executeQuery("SELECT 1");
assertTrue  (rs.next());
assertEquals(1, rs.getInt(1));

...

java.sql.SQLException: Communication link failure:
java.net.SocketException, underlying cause:
Software caused connection abort: recv failed

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: Software caused connection abort: recv failed

STACKTRACE:

java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:222)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1385)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1532)
...
** END NESTED EXCEPTION **
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1707)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1923)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:1218)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2233)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2181)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1159)


Suggested fix:
Connections should properly reconnect when the Socket times out
or the connection is lost some other way.

Please contact me for a complete TestSuite based on your Regression Tests.

打印本文 打印本文 关闭窗口 关闭窗口