Skip to content

Commit 0ce4f54

Browse files
committed
Bug#34338950 Fix xapi crash when disconnect
If mysqlx_session_close is called after a disconnect, xapi would crash. Change-Id: I301fc4f16b0cb43bf27b0e679e744480c3ebb6ec
1 parent 863f45d commit 0ce4f54

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

common/session.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,10 @@ Pooled_session::Pooled_session(cdk::ds::Multi_source &ds)
708708

709709
Pooled_session::~Pooled_session()
710710
{
711-
release();
711+
//Let's catch any errors when releasing the session
712+
try {
713+
release();
714+
} catch (...) {}
712715
}
713716

714717
void Pooled_session::release()

xapi/tests/xapi-t.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,3 +3608,40 @@ TEST_F(xapi, normalize_ssl_options)
36083608
}
36093609

36103610
}
3611+
3612+
TEST_F(xapi, bug34338950)
3613+
{
3614+
SKIP_IF_NO_XPLUGIN;
3615+
AUTHENTICATE();
3616+
3617+
mysqlx_error_t *error;
3618+
mysqlx_session_t *sess;
3619+
3620+
sess = mysqlx_get_session_from_url(get_uri().c_str(), &error);
3621+
3622+
if (sess == NULL) {
3623+
std::stringstream str;
3624+
str << "Unexpected error: " << mysqlx_error_message(error) << endl;
3625+
mysqlx_free(error);
3626+
FAIL() << str.str();
3627+
}
3628+
3629+
mysqlx_result_t *res = exec_sql(sess, "SELECT CONNECTION_ID() as _pid");
3630+
3631+
if (!res) throw "Failed to query CONNECTION_ID() ";
3632+
3633+
mysqlx_row_t *row = mysqlx_row_fetch_one(res);
3634+
3635+
if (!row) throw "Failed to get value of CONNECTION_ID()";
3636+
3637+
uint64_t pid;
3638+
if (RESULT_OK != mysqlx_get_uint(row, 0, &pid))
3639+
throw "Failed to get value of CONNECTION_ID()";
3640+
3641+
std::string kill_connection = "KILL ";
3642+
kill_connection += std::to_string(pid);
3643+
3644+
exec_sql(kill_connection.c_str());
3645+
3646+
mysqlx_session_close(sess);
3647+
}

0 commit comments

Comments
 (0)