Bug #107693 connector call seeion close won't return when connect to a router
Submitted: 29 Jun 2022 3:00 Modified: 28 Feb 2023 20:30
Reporter: bingo yang Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / C++ Severity:S2 (Serious)
Version:8.0.29 OS:Any
Assigned to: CPU Architecture:Any
Tags: connector c++

[29 Jun 2022 3:00] bingo yang
Description:
When connect to mysql router using connector c++, call seession will get stuck.

steps:
1.down load connector c++ 8.0.29 from this page https://dev.mysql.com/downloads/connector/cpp/

2. create a session to connect a mysql router using mysqlx_get_session_from_options or new mysqlx::Session

3. call mysqlx_session_close or mySession->close();

4. the mysqlx_session_close won' return;

addition: connect to mysql server directly is ok 

How to repeat:
//the below is the c version, the c++ plus version has the same issue too

int MysqlApiTest::cTest()
{
std::string MysqlApiTest::mUser = "root";
std::string MysqlApiTest::mPwd = "toot";
std::string MysqlApiTest::mIp = "10.3.68.8";
int MysqlApiTest::mPort = 6448;// 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_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;
    }

    mysqlx_session_close(sess);// will never return

    return 0;
}

Suggested fix:
The code wait in row m_protocol.rcv_Reply(*this).wait() in function void Session::close() in mysql-connector-cpp-8.0.29\cdk\mysqlx\session.cc
[30 Jun 2022 16:05] MySQL Verification Team
Hello,

Thank you for the bug report and feedback.

Regards,
Ashwini Patil
[28 Feb 2023 18:03] Luis Silva
Posted by developer:
 
Now connector will not wait for Reply after ConnectionClose message.
[28 Feb 2023 20:30] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/C++ 8.0.33 release, and here's the proposed changelog entry from the documentation team:

When a connection was made to MySQL Router, rather than directly to the
server, closing a session using mysqlx_session_close was not possible.
Now, the connector no longer waits for a reply to the call before closing
the session.

Thank you for the bug report.