Bug #107692 connector xapi call mysqlx_session_close crash when network is disconnect
Submitted: 29 Jun 2022 2:43 Modified: 4 Aug 2023 10:13
Reporter: bingo yang Email Updates:
Status: Closed Impact on me:
Category:Connector / C++ Severity:S2 (Serious)
Version:8.0.33 OS:Windows
Assigned to: CPU Architecture:Any

[29 Jun 2022 2:43] bingo yang
Connector/C++ 8.0.29 call mysqlx_session_close crash when network is disconnect


I download Connector/C++ 8.0.29 From thi page https://dev.mysql.com/downloads/connector/cpp/

using vs 2017 construct a resolution.

1. First create a session using mysqlx_get_session_from_options.
The mysql server and the client are in different machine,

2. make the client disconnect the Internet

3. call mysqlx_session_close: the application will crash; try cach is not work

How to repeat:
int MysqlApiTest::cTest()
std::string MysqlApiTest::mUser = "root";
std::string MysqlApiTest::mPwd = "toot";
std::string MysqlApiTest::mIp = "";
int MysqlApiTest::mPort = 33060;// 33060;//6448
std::string MysqlApiTest::mDbName = "db_test";

    mysqlx_session_t  *sess = NULL;
    std::string mCurErrcode;

    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()),

    sess = mysqlx_get_session_from_options(opt, &error);

    if (sess == NULL)
        mCurErrcode = mysqlx_error_num(error);  //if option error, mCurErrcode = 0
        std::string str(mysqlx_error_message(error));
        return 1;
    printf("\nSession create");
    if (error != NULL) {
        error = NULL;

    try {
    catch (const ::mysqlx::Error&) { }   
    catch (const std::out_of_range&) { } 
    catch (const std::exception &e) 
        return 0;
    catch (const char *e) 
    catch (...) 

    return 0;

Suggested fix:
the exception is throwed in mysql-connector-cpp-8.0.29\cdk\mysqlx\session.cc void Session::close().

The try catch in mysqlx.cc (void STDCALL mysqlx_session_close(mysqlx_session_struct *sess)) seemed not work
[30 Jun 2022 16:09] MySQL Verification Team

Thank you for the bug report and feedback.

Ashwini Patil
[1 Aug 2022 16:48] Christine Cole
Posted by developer:
Fixed as of the upcoming MySQL Connector/C++ 8.0.31 release, and here's the proposed changelog entry from the documentation team:

If an application program called mysqlx_session_close after disconnecting
from the Internet, an exception from Connector/C++ could cause the
application to halt unexpectedly.

Thank you for the bug report.
[14 Jul 2023 8:26] bingo yang
I have tested the bug using mysql server 8.0.31 without router and connetor 8.0.31/32 both using c version api. It still cause crash. Cloud you please check it in again? thanks
[4 Aug 2023 10:13] bingo yang
8.0.33 connector + 8.0.31 mysql server:  when created the session without OPENSSL  "OPT_SSL_MODE(SSL_MODE_DISABLED)", it will crash. if enable OPENSSL  ,wont't crash.