From d0acdcd5c2fd91ab2edddcad8cd2f4dc44160c54 Mon Sep 17 00:00:00 2001 From: Valentin Rakush Date: Mon, 4 May 2020 14:38:11 +0000 Subject: [PATCH] Crashing often with strange new error (Error setting MYSQL_OPTION_MULTI_STATEMENTS) (cherry picked from commit 4fc76a25900051b068e9282097550aa2549eacd1) --- lib/MySQL_Session.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index edf555703..0877924c1 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -2308,7 +2308,36 @@ bool MySQL_Session::handler_again___status_SETTING_MULTI_STMT(int *_rc) { NEXT_IMMEDIATE_NEW(st); } else { if (rc==-1) { - proxy_error("Error setting multistatement on server %s , %d : %d, %s\n", myconn->parent->address, myconn->parent->port, mysql_errno(myconn->mysql), mysql_error(myconn->mysql)); + // the command failed + int myerr=mysql_errno(myconn->mysql); + if (myerr >= 2000) { + bool retry_conn=false; + // client error, serious + proxy_error("Detected a broken connection during setting MYSQL_OPTION_MULTI_STATEMENTS on %s , %d : %d, %s\n", myconn->parent->address, myconn->parent->port, myerr, mysql_error(myconn->mysql)); + //if ((myds->myconn->reusable==true) && ((myds->myprot.prot_status & SERVER_STATUS_IN_TRANS)==0)) { + if ((myds->myconn->reusable==true) && myds->myconn->IsActiveTransaction()==false && myds->myconn->MultiplexDisabled()==false) { + retry_conn=true; + } + myds->destroy_MySQL_Connection_From_Pool(false); + myds->fd=0; + if (retry_conn) { + myds->DSS=STATE_NOT_INITIALIZED; + NEXT_IMMEDIATE_NEW(CONNECTING_SERVER); + } + *_rc=-1; // an error happened, we should destroy the Session + return ret; + } else { + proxy_warning("Error during MYSQL_OPTION_MULTI_STATEMENTS : %d, %s\n", myerr, mysql_error(myconn->mysql)); + // we won't go back to PROCESSING_QUERY + st=previous_status.top(); + previous_status.pop(); + char sqlstate[10]; + sprintf(sqlstate,"%s",mysql_sqlstate(myconn->mysql)); + client_myds->myprot.generate_pkt_ERR(true,NULL,NULL,1,mysql_errno(myconn->mysql),sqlstate,mysql_error(myconn->mysql)); + myds->destroy_MySQL_Connection_From_Pool(true); + myds->fd=0; + RequestEnd(myds); + } } else { // rc==1 , nothing to do for now }