diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c index 0ce71dfc..9cebe6df 100644 --- a/libmariadb/mariadb_lib.c +++ b/libmariadb/mariadb_lib.c @@ -382,6 +382,15 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, { NET *net= &mysql->net; int result= -1; + + /* CONC-589: If reconnect option was specified, we have to check if the connection + (socket) is still available */ + if (command != COM_QUIT && mysql->options.reconnect && ma_pvio_is_alive(mysql->net.pvio)) + { + mysql->net.pvio= NULL; + mysql->net.error= 1; + } + if (mysql->net.pvio == 0) { /* Do reconnect if possible */ diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index aaea1f8f..58374593 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -1998,7 +1998,54 @@ static int test_conc748(MYSQL *my __attribute__((unused))) } #endif +static int test_conc589(MYSQL *my) +{ + MYSQL *mysql= mysql_init(NULL); + MYSQL_RES *result; + int rc; + my_bool reconnect= 1, verify= 0; + unsigned long last_thread_id= 0; + + mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect); + mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify); + + if (!my_test_connect(mysql, hostname, username, + password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS)) + { + diag("error: %s", mysql_error(mysql)); + return FAIL; + } + + rc= mysql_query(mysql, "SET SESSION wait_timeout=5"); + check_mysql_rc(rc, mysql); + + last_thread_id= mysql_thread_id(mysql); + if ((rc= mysql_query(mysql, "SELECT 1")) || (result= mysql_store_result(mysql)) == NULL) + check_mysql_rc(rc, mysql); + + mysql_free_result(result); + sleep(10); + + if ((rc= mysql_query(mysql, "SELECT 2")) || (result= mysql_store_result(mysql)) == NULL) + check_mysql_rc(rc, mysql); + mysql_free_result(result); + FAIL_IF(mysql_thread_id(mysql) == last_thread_id, "Expected new connection id"); + last_thread_id= mysql_thread_id(mysql); + + mysql_kill(my, last_thread_id); + + sleep(10); + + if ((rc= mysql_query(mysql, "SELECT 3")) || (result= mysql_store_result(mysql)) == NULL) + check_mysql_rc(rc, mysql); + mysql_free_result(result); + FAIL_IF(mysql_thread_id(mysql) == last_thread_id, "Expected new connection id"); + mysql_close(mysql); + return OK; +} + struct my_tests_st my_tests[] = { + {"test_conc589", test_conc589, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) {"test_conc748", test_conc748, TEST_CONNECTION_NONE, 0, NULL, NULL}, #endif