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: 芳彬 杨 Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / C++ Severity:S2 (Serious)
Version:8.0.33 OS:Windows
Assigned to: CPU Architecture:Any

[29 Jun 2022 2:43] 芳彬 杨
Description:
Connector/C++ 8.0.29 call mysqlx_session_close crash when network is disconnect

Steps:

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 = "10.3.68.8";
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()),
        OPT_DB(mDbName.c_str()),
        OPT_SSL_MODE(SSL_MODE_DISABLED),
        OPT_COMPRESSION(MYSQLX_COMPRESSION_DISABLED),
        PARAM_END);

    sess = mysqlx_get_session_from_options(opt, &error);
    mysqlx_free(opt);

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

    try {
        mysqlx_session_close(sess);
    }
    catch (const ::mysqlx::Error&) { }   
    catch (const std::out_of_range&) { } 
    catch (const std::exception &e) 
    {
        throw;
        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
Hello,

Thank you for the bug report and feedback.

Regards,
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] 芳彬 杨
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] 芳彬 杨
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.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.057 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.