| Bug #120126 | mysql connector c xdev get stuck when connect in keepalived and mysql server restart | ||
|---|---|---|---|
| Submitted: | 23 Mar 2:53 | Modified: | 25 Mar 9:34 |
| Reporter: | 芳彬 杨 | Email Updates: | |
| Status: | Open | Impact on me: | |
| Category: | Connector / C | Severity: | S2 (Serious) |
| Version: | 9.6.0 and 8.0.33 | OS: | Ubuntu (20.04) |
| Assigned to: | CPU Architecture: | Any | |
[23 Mar 2:53]
芳彬 杨
[25 Mar 1:41]
芳彬 杨
Sorry~ something is missing for reproduce step. For step 5 "5 restart machine A's mysqlserver and call the below in a "while(can add some thread sleep)" together mysqlx_sql(mySessiont, sql.c_str(), sql.length()); //the sql is a simple "select" query" should be "5 restart machine A's mysqlserver and call the below in a "while(can add some thread sleep)" together mysqlx_sql(mySessiont, sql.c_str(), sql.length()); and if the errcode is 11 close the seccion(mysqlx_session_close) and recreate using the above parameter(mysqlx_get_session_from_options) the continue call mysqlx_sql //the sql in mysqlx_sql is a simple "select" query //and must call the above repeated at the same time when mysql server restart, if wait several minutes, it won't happen " when restart mysql server, the process is like this: mysqlx_sql fail, errcode 11 mysqlx_get_session_from_options fail for several times, errcode is 111 mysqlx_get_session_from_options success mysqlx_sql fail, and get stuck 15minutes
[25 Mar 9:03]
芳彬 杨
Here is my test code with 9.6.0:
may need restart the mysql serveral times:
mysqlx_session_t* MysqlApiTest::_Bug120126_Connect()
{
mysqlx_session_t *sess = NULL;
unsigned int curErrcode;
mysqlx_session_options_t *opt = NULL;
mysqlx_error_t *error = NULL;
opt = mysqlx_session_options_new();
int optRes = mysqlx_session_option_set(opt,
OPT_HOST(mIp.c_str()), OPT_PORT(mPort),
OPT_USER(mUser.c_str()), OPT_PWD(mPwd.c_str()),
OPT_DB(mDbName.c_str()),
OPT_COMPRESSION(MYSQLX_COMPRESSION_DISABLED),
OPT_CONNECT_TIMEOUT(10*1000),
OPT_READ_TIMEOUT(10000),
OPT_WRITE_TIMEOUT(15000),
PARAM_END);
sess = mysqlx_get_session_from_options(opt, &error);
mysqlx_free(opt);
if (sess == NULL)
{
std::cout << "session create null" << std::endl;
curErrcode = mysqlx_error_num(error); //if option error, mCurErrcode = 0
std::string str(mysqlx_error_message(error));
std::cout << str << std::endl;
mysqlx_free(error);
return sess;
}
std::cout << "session create success" << std::endl;
if (error != NULL) {
mysqlx_free(error);
error = NULL;
}
return sess;
}
void MysqlApiTest::Bug120126Test_keepAlived()
{
std::cout << "\nBug120126Test_keepAlived begin: mysql server restart behind alived will get stuck" << std::endl;
mysqlx_session_t *sess = NULL;
unsigned int curErrcode;
sess = _Bug120126_Connect();
if (sess == NULL)
{
return;
}
std::chrono::time_point<std::chrono::system_clock> begin_time = std::chrono::system_clock::now();
const std::string sql = "SELECT * FROM app_shared_data limit 10;";
long sql_succ_count = 0;
long recon_count = 0;
while (true && sess)
{
std::chrono::time_point<std::chrono::system_clock> begin_sql_time = std::chrono::system_clock::now();
mysqlx_result_t* result = mysqlx_sql(sess, sql.c_str(), sql.length());
std::chrono::time_point<std::chrono::system_clock> end_sql_time = std::chrono::system_clock::now();
std::chrono::milliseconds sql_cost = std::chrono::duration_cast<std::chrono::milliseconds>(end_sql_time - begin_sql_time);
if (result != NULL)
{
sql_succ_count++;
mysqlx_free(result);
result = NULL;
if (sql_succ_count % 10 == 0)
{
std::cout << "mysqlx_sql success:"<< sql_succ_count << std::endl;
}
//sleep
std::this_thread::sleep_for(std::chrono::seconds(1));
}
else {
if (sql_cost.count() > 10 * 1000)
{
std::cout << "mysqlx_sql fail and cost too long:"<< sql_cost.count() << std::endl;
}
sql_succ_count = 0;
curErrcode = mysqlx_error_num(sess); //if option error, mCurErrcode = 0
std::string str(mysqlx_error_message(sess));
std::cout << "mysqlx_sql fail:" << curErrcode << "," << str << std::endl;
if(curErrcode == 11
|| curErrcode == 104
|| curErrcode == 23
|| curErrcode == 15)
{
recon_count = 0;
std::cout << "close session and do reconnect" << std::endl;
//free and reconnect
mysqlx_session_close(sess);
sess = NULL;
while ((sess = _Bug120126_Connect()) == NULL)
{
recon_count++;
std::cout << "reconnect: " << recon_count << std::endl;
//sleep
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}
}
std::chrono::time_point<std::chrono::system_clock> end_time = std::chrono::system_clock::now();
std::chrono::milliseconds totaltime = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - begin_time);
if (totaltime.count() > 20 * 60 * 1000)//20min
{
if(sess)
{
mysqlx_session_close(sess);
sess = NULL;
std::cout << "run too long, and break" << std::endl;
break;
}
}
}
std::cout << "Bug120126Test_keepAlived end" << std::endl;
}
[25 Mar 9:34]
芳彬 杨
Here is my log(I restart the mysqlserver twice) and the client must run in machine B: Bug120126Test_keepAlived begin: mysql server restart behind alived will get stuck session create success mysqlx_sql fail:11,CDK Error: OpenSSL: error:0A000126:SSL routines::unexpected eof while reading close session and do reconnect session create null CDK Error: Connection refused (generic:111) reconnect: 1 session create null CDK Error: Connection refused (generic:111) reconnect: 2 session create null CDK Error: Connection refused (generic:111) reconnect: 3 session create success mysqlx_sql success:10 mysqlx_sql fail and cost too long:Bug120126Test_keepAlived begin: mysql server restart behind alived will get stuck session create success mysqlx_sql fail:11,CDK Error: OpenSSL: error:0A000126:SSL routines::unexpected eof while reading close session and do reconnect session create null CDK Error: Connection refused (generic:111) reconnect: 1 session create null CDK Error: Connection refused (generic:111) reconnect: 2 session create null CDK Error: Connection refused (generic:111) reconnect: 3 session create success mysqlx_sql success:10 mysqlx_sql fail and cost too long:938196 mysqlx_sql fail:110,CDK Error: Connection timed out (generic:110) mysqlx_sql fail:32,CDK Error: Broken pipe (generic:32) mysqlx_sql fail:1,CDK Error: Can't write message while another one is being written close session and do reconnect session create success mysqlx_sql success:10 mysqlx_sql success:20 mysqlx_sql success:30 mysqlx_sql fail:110,CDK Error: Connection timed out (generic:110) mysqlx_sql fail:32,CDK Error: Broken pipe (generic:32) mysqlx_sql fail:1,CDK Error: Can't write message while another one is being written close session and do reconnect session create success mysqlx_sql success:10 mysqlx_sql success:20 mysqlx_sql success:30
