1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-08 14:02:17 +03:00

Fixed crash/undefined behaviour when running large amount of threads:

replaced select() with poll()
Added conneciton timeout support for windows platforms
This commit is contained in:
holzboote@googlemail.com
2013-08-01 09:56:36 +02:00
parent 077afd8e10
commit b5db6c127f
4 changed files with 104 additions and 79 deletions

View File

@@ -522,7 +522,10 @@ static int test_reconnect(MYSQL *mysql)
diag("Thread_id before kill: %lu", mysql_thread_id(mysql1));
mysql_kill(mysql, mysql_thread_id(mysql1));
sleep(2);
rc= mysql_query(mysql1, "SELECT 1 FROM DUAL LIMIT 0");
FAIL_IF(rc == 0, "error expected");
rc= mysql_query(mysql1, "SELECT 1 FROM DUAL LIMIT 0");
check_mysql_rc(rc, mysql1);
diag("Thread_id after kill: %lu", mysql_thread_id(mysql1));
@@ -581,6 +584,25 @@ int test_conc26(MYSQL *my)
return OK;
}
int test_connection_timeout(MYSQL *my)
{
unsigned int timeout= 5;
time_t start, elapsed;
MYSQL *mysql= mysql_init(NULL);
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (unsigned int *)&timeout);
start= time(NULL);
if (mysql_real_connect(mysql, "192.168.1.101", "notexistinguser", "password", schema, port, NULL, CLIENT_REMEMBER_OPTIONS))
{
diag("Error expected - maybe you have to change hostname");
return FAIL;
}
elapsed= time(NULL) - start;
diag("elapsed: %d", elapsed);
mysql_close(mysql);
FAIL_IF(elapsed +1 > timeout, "timeout ignored")
return OK;
}
struct my_tests_st my_tests[] = {
{"test_bug20023", test_bug20023, TEST_CONNECTION_NEW, 0, NULL, NULL},
{"test_bug31669", test_bug31669, TEST_CONNECTION_NEW, 0, NULL, NULL},
@@ -591,6 +613,7 @@ struct my_tests_st my_tests[] = {
{"test_reconnect", test_reconnect, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc21", test_conc21, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
{"test_conc26", test_conc26, TEST_CONNECTION_NONE, 0, NULL, NULL},
{"test_connection_timeout", test_connection_timeout, TEST_CONNECTION_NONE, 0, NULL, NULL},
{NULL, NULL, 0, 0, NULL, NULL}
};

View File

@@ -45,8 +45,9 @@ int thread_conc27(void);
DWORD WINAPI thread_conc27(void);
#endif
#define THREAD_NUM 150
#define THREAD_NUM 1800
/* run this test as root and increase the number of handles (ulimit -n) */
static int test_conc_27(MYSQL *mysql)
{
@@ -70,6 +71,9 @@ static int test_conc_27(MYSQL *mysql)
rc= mysql_query(mysql, "INSERT INTO t_conc27 VALUES(0)");
check_mysql_rc(rc, mysql);
rc= mysql_query(mysql, "SET GLOBAL max_connections=100000");
check_mysql_rc(rc, mysql);
pthread_mutex_init(&LOCK_test, NULL);
for (i=0; i < THREAD_NUM; i++)
{
@@ -121,7 +125,7 @@ DWORD WINAPI thread_conc27(void)
if(!mysql_real_connect(mysql, hostname, username, password, schema,
port, socketname, 0))
{
diag("Error: %s", mysql_error(mysql));
diag(">Error: %s", mysql_error(mysql));
mysql_close(mysql);
mysql_thread_end();
goto end;
@@ -130,7 +134,6 @@ DWORD WINAPI thread_conc27(void)
rc= mysql_query(mysql, "UPDATE t_conc27 SET a=a+1");
check_mysql_rc(rc, mysql);
pthread_mutex_unlock(&LOCK_test);
rc= mysql_query(mysql, "SELECT SLEEP(5)");
check_mysql_rc(rc, mysql);
if (res= mysql_store_result(mysql))
mysql_free_result(res);