Skip to content

Commit

Permalink
修复MYSQL 部分ERROR PACKET 包,造成 ERROR 2013 (HY000): Lost connection to MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuam committed Nov 4, 2016
1 parent 7e888dd commit 5a3d170
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ public void errorResponse(byte[] data, BackendConnection conn) {
session.releaseConnectionIfSafe(conn, LOGGER.isDebugEnabled(), false);
ErrorPacket err = new ErrorPacket();
err.read(data);

String errmsg = new String(err.message);
this.setFail(errmsg);
LOGGER.warn("error response from " + conn + " err " + errmsg + " code:"
+ err.errno);

LOGGER.warn("error response from " + conn + " err " + errmsg + " code:" + err.errno);

this.tryErrorFinished(this.decrementCountBy(1));
}
Expand Down Expand Up @@ -187,13 +188,13 @@ protected ErrorPacket createErrPkg(String errmgs) {
lock.unlock();
}
err.errno = ErrorCode.ER_UNKNOWN_ERROR;
err.message = StringUtil.encode(errmgs, session.getSource()
.getCharset());
err.message = StringUtil.encode(errmgs, session.getSource().getCharset());
return err;
}

protected void tryErrorFinished(boolean allEnd) {
if (allEnd && !session.closed()) {

if (errorRepsponsed.compareAndSet(false, true)) {
createErrPkg(this.error).write(session.getSource());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,25 @@ private void backConnectionErr(ErrorPacket errPkg, BackendConnection conn) {
session.releaseConnectionIfSafe(conn, LOGGER.isDebugEnabled(), false);

source.setTxInterrupt(errmgs);

/**
* TODO: 修复全版本BUG
*
* BUG复现:
* 1、MysqlClient: SELECT 9223372036854775807 + 1;
* 2、MyCatServer: ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807 + 1)'
* 3、MysqlClient: ERROR 2013 (HY000): Lost connection to MySQL server during query
*
* Fixed后
* 1、MysqlClient: SELECT 9223372036854775807 + 1;
* 2、MyCatServer: ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807 + 1)'
* 3、MysqlClient: ERROR 1690 (22003): BIGINT value is out of range in '(9223372036854775807 + 1)'
*
*/
// 由于 pakcetId != 1 造成的问题
errPkg.packetId = 1;
errPkg.write(source);

recycleResources();
}

Expand Down

0 comments on commit 5a3d170

Please sign in to comment.