summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <holyfoot/hf@mysql.com/hfmain.(none)>2008-03-19 15:51:22 +0400
committerunknown <holyfoot/hf@mysql.com/hfmain.(none)>2008-03-19 15:51:22 +0400
commit4018b13915c2fa972cf4da90ab1b2272b855a490 (patch)
treeac5bd6173e6b2ef97f31084bb08dd1d024b4dc2d
parent012aab7d8bf7ae9c30751a6d5f666c7731ecfdf3 (diff)
downloadmariadb-git-4018b13915c2fa972cf4da90ab1b2272b855a490.tar.gz
Bug #33334 mysqltest_embedded crashes when disconnecting before reap.
Before breaking the connection we have to check that there's no query executing at the moment. Otherwise it can lead to crash in embedded server. client/mysqltest.c: Bug #33334 mysqltest_embedded crashes when disconnecting before reap. Wait until the query thread is finished before we break the connection. Waiting part moved to a separate wait_query_thread_end() function mysql-test/r/flush.result: Bug #33334 mysqltest_embedded crashes when disconnecting before reap. test result mysql-test/t/flush.test: Bug #33334 mysqltest_embedded crashes when disconnecting before reap. test case
-rw-r--r--client/mysqltest.c34
-rw-r--r--mysql-test/r/flush.result1
-rw-r--r--mysql-test/t/flush.test9
3 files changed, 35 insertions, 9 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 88575c26bc6..b028794295c 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -542,6 +542,17 @@ static int do_send_query(struct st_connection *cn, const char *q, int q_len,
return 0;
}
+static void wait_query_thread_end(struct st_connection *con)
+{
+ if (!con->query_done)
+ {
+ pthread_mutex_lock(&con->mutex);
+ while (!con->query_done)
+ pthread_cond_wait(&con->cond, &con->mutex);
+ pthread_mutex_unlock(&con->mutex);
+ }
+}
+
#else /*EMBEDDED_LIBRARY*/
#define do_send_query(cn,q,q_len,flags) mysql_send_query(&cn->mysql, q, q_len)
@@ -3939,7 +3950,14 @@ void do_close_connection(struct st_command *command)
con->mysql.net.vio = 0;
}
}
-#endif
+#else
+ /*
+ As query could be still executed in a separate theread
+ we need to check if the query's thread was finished and probably wait
+ (embedded-server specific)
+ */
+ wait_query_thread_end(con);
+#endif /*EMBEDDED_LIBRARY*/
if (con->stmt)
mysql_stmt_close(con->stmt);
con->stmt= 0;
@@ -4229,6 +4247,9 @@ void do_connect(struct st_command *command)
(int) (sizeof(connections)/sizeof(struct st_connection)));
}
+#ifdef EMBEDDED_LIBRARY
+ con_slot->query_done= 1;
+#endif
if (!mysql_init(&con_slot->mysql))
die("Failed on mysql_init()");
if (opt_compress || con_compress)
@@ -5716,16 +5737,11 @@ void run_query_normal(struct st_connection *cn, struct st_command *command,
}
#ifdef EMBEDDED_LIBRARY
/*
- Here we handle 'reap' command, so we need to check if the
- query's thread was finished and probably wait
+ Here we handle 'reap' command, so we need to check if the
+ query's thread was finished and probably wait
*/
else if (flags & QUERY_REAP_FLAG)
- {
- pthread_mutex_lock(&cn->mutex);
- while (!cn->query_done)
- pthread_cond_wait(&cn->cond, &cn->mutex);
- pthread_mutex_unlock(&cn->mutex);
- }
+ wait_query_thread_end(cn);
#endif /*EMBEDDED_LIBRARY*/
if (!(flags & QUERY_REAP_FLAG))
DBUG_VOID_RETURN;
diff --git a/mysql-test/r/flush.result b/mysql-test/r/flush.result
index ce64e09c1d3..778f138f29d 100644
--- a/mysql-test/r/flush.result
+++ b/mysql-test/r/flush.result
@@ -72,3 +72,4 @@ flush tables with read lock;
unlock tables;
drop table t1, t2;
set session low_priority_updates=default;
+select benchmark(200, (select sin(1))) > 1000;
diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test
index 72efa8a2ee6..4c6d4265600 100644
--- a/mysql-test/t/flush.test
+++ b/mysql-test/t/flush.test
@@ -164,4 +164,13 @@ drop table t1, t2;
set session low_priority_updates=default;
+#
+# Bug #33334 mysqltest_embedded crashes when disconnecting before reap
+#
+
+connect (con1,localhost,root,,);
+send select benchmark(200, (select sin(1))) > 1000;
+disconnect con1;
+connection default;
+
# End of 5.0 tests