You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-01 06:27:04 +03:00
CONC-589: First query fails after reconnect
If automatic reconnect is enabled (MYSQL_OPT_RECONNECT) it is mandatory to check if the connection/socket is still alive before sending a command to the server (unless the command is COM_QUIT).
This commit is contained in:
@ -382,6 +382,15 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg,
|
|||||||
{
|
{
|
||||||
NET *net= &mysql->net;
|
NET *net= &mysql->net;
|
||||||
int result= -1;
|
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)
|
if (mysql->net.pvio == 0)
|
||||||
{
|
{
|
||||||
/* Do reconnect if possible */
|
/* Do reconnect if possible */
|
||||||
|
@ -1998,7 +1998,54 @@ static int test_conc748(MYSQL *my __attribute__((unused)))
|
|||||||
}
|
}
|
||||||
#endif
|
#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[] = {
|
struct my_tests_st my_tests[] = {
|
||||||
|
{"test_conc589", test_conc589, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||||
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
|
#if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
|
||||||
{"test_conc748", test_conc748, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
{"test_conc748", test_conc748, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user