1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-01 06:27:04 +03:00

CONC-760: valid named pipe connection is closed

Fixed different behavior of pvio_is_alive (which was first used
with fix of CONC-589). Both for sockets and named pipe the function
now returns true if the connection is alive, otherwise false.
This commit is contained in:
Georg Richter
2025-02-27 07:48:58 +01:00
parent bbf07912ec
commit aa240cd181
3 changed files with 80 additions and 10 deletions

View File

@ -385,7 +385,7 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg,
/* 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))
if (command != COM_QUIT && mysql->options.reconnect && !ma_pvio_is_alive(mysql->net.pvio))
{
ma_pvio_close(mysql->net.pvio);
mysql->net.pvio= NULL;

View File

@ -1082,10 +1082,10 @@ my_bool pvio_socket_is_alive(MARIADB_PVIO *pvio)
res= poll(&poll_fd, 1, 0);
if (res <= 0) /* timeout or error */
return FALSE;
if (!(poll_fd.revents & (POLLIN | POLLPRI)))
return FALSE;
return TRUE;
if (!(poll_fd.revents & (POLLIN | POLLPRI)))
return TRUE;
return FALSE;
#else
/* We can't use the WSAPoll function, it's broken :-(
(see Windows 8 Bugs 309411 - WSAPoll does not report failed connections)
@ -1098,8 +1098,8 @@ my_bool pvio_socket_is_alive(MARIADB_PVIO *pvio)
res= select((int)csock->socket + 1, &sfds, NULL, NULL, &tv);
if (res > 0 && FD_ISSET(csock->socket, &sfds))
return TRUE;
return FALSE;
return TRUE;
#endif
}
/* }}} */

View File

@ -2002,7 +2002,6 @@ static int test_conc748(MYSQL *my __attribute__((unused)))
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;
@ -2022,6 +2021,72 @@ static int test_conc589(MYSQL *my)
rc= mysql_query(mysql, "SET SESSION wait_timeout=5");
check_mysql_rc(rc, mysql);
last_thread_id= mysql_thread_id(mysql);
rc= mysql_query(mysql, "SET @a:=1");
check_mysql_rc(rc, mysql);
sleep(10);
rc= mysql_query(mysql, "SET @a:=2");
check_mysql_rc(rc, mysql);
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);
rc= mysql_query(mysql, "SET @a:=3");
check_mysql_rc(rc, mysql);
FAIL_IF(mysql_thread_id(mysql) == last_thread_id, "Expected new connection id");
mysql_close(mysql);
return OK;
}
#ifdef WIN32
static int test_conc760(MYSQL *my)
{
MYSQL *mysql= mysql_init(NULL);
MYSQL_RES *result;
MYSQL_ROW row;
int rc;
my_bool reconnect= 1, verify= 0;
unsigned long last_thread_id= 0;
unsigned int protocol= MYSQL_PROTOCOL_PIPE;
my_bool have_named_pipe= 0;
SKIP_MAXSCALE;
rc= mysql_query(my, "select @@named_pipe");
check_mysql_rc(rc, mysql);
if ((result= mysql_store_result(my)))
{
if((row= mysql_fetch_row(result)))
have_named_pipe= atoi(row[0]);
mysql_free_result(result);
}
if (!have_named_pipe)
{
diag("Server doesn't support named pipes");
return SKIP;
}
mysql_options(mysql, MYSQL_OPT_RECONNECT, &reconnect);
mysql_options(mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &verify);
mysql_options(mysql, MYSQL_OPT_PROTOCOL, &protocol);
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);
@ -2029,8 +2094,9 @@ static int test_conc589(MYSQL *my)
mysql_free_result(result);
sleep(10);
if ((rc= mysql_query(mysql, "SELECT 2")) || (result= mysql_store_result(mysql)) == NULL)
rc= mysql_query(mysql, "SELECT 2");
check_mysql_rc(rc, mysql);
if (result= mysql_store_result(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);
@ -2046,8 +2112,12 @@ static int test_conc589(MYSQL *my)
mysql_close(mysql);
return OK;
}
#endif
struct my_tests_st my_tests[] = {
#ifdef WIN32
{"test_conc760", test_conc760, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
#endif
{"test_conc589", test_conc589, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
#ifdef HAVE_test_conc748
{"test_conc748", test_conc748, TEST_CONNECTION_NONE, 0, NULL, NULL},