From: prabakaran thirumalai Date: July 17 2012 11:35am Subject: bzr push into mysql-trunk branch (prabakaran.thirumalai:4068 to 4069) Bug#13002460 List-Archive: http://lists.mysql.com/commits/144457 X-Bug: 13002460 Message-Id: <201207171135.q6HBZRWd001296@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4069 prabakaran thirumalai 2012-07-17 Bug#13002460 CRASH WHEN SHUTTING DOWN SERVER AND TOGGLING EVENT_SCHEDULER AT RUNTIME Analysis: static objects declared in Events (events.cc) is not guarded by mutex. This leads to race condition during shutdown. Client connection thread which toggles EVENT_SCHEDULER calls scheduler->start() or scheduler->stop() depending on the flag set. During shutdown, close_connections() calls Events::deinit() from kill_server_thread, which destroys scheduler object before waiting for all client connection threads to end. This leads to scheduler->start() or scheduler->stop() being called on destroyed scheduler object Fix: Moved Events::deinit() call after stopping all the client connection threads. Additional Notes: No test case added because send_shutdown command of mtr does not call Events::deinit(). Moreover scenario described in the bug description cannot be synchronized using mtr as they are two different process(mysqlslap and mysqladmin) modified: sql/events.cc sql/mysqld.cc 4068 Vasil Dimov 2012-07-17 [merge] Merge mysql-5.6 -> mysql-trunk modified: mysql-test/include/subquery_sj.inc storage/innobase/dict/dict0dict.cc storage/innobase/dict/dict0stats.cc storage/innobase/include/univ.i === modified file 'sql/events.cc' --- a/sql/events.cc 2012-07-02 05:46:13 +0000 +++ b/sql/events.cc 2012-07-17 11:32:03 +0000 @@ -913,8 +913,11 @@ end: if (res) { delete db_repository; + db_repository= NULL; delete event_queue; + event_queue= NULL; delete scheduler; + scheduler= NULL; } delete thd; /* Remember that we don't have a THD */ @@ -1065,12 +1068,16 @@ Events::dump_internal_status() bool Events::start() { - return scheduler->start(); + bool ret= false; + if (scheduler) ret= scheduler->start(); + return ret; } bool Events::stop() { - return scheduler->stop(); + bool ret= false; + if (scheduler) ret= scheduler->stop(); + return ret; } /** === modified file 'sql/mysqld.cc' --- a/sql/mysqld.cc 2012-07-17 07:52:54 +0000 +++ b/sql/mysqld.cc 2012-07-17 11:32:03 +0000 @@ -1388,8 +1388,6 @@ static void close_connections(void) } mysql_mutex_unlock(&LOCK_thread_count); - Events::deinit(); - sql_print_information("Shutting down slave threads"); end_slave(); @@ -1424,7 +1422,13 @@ static void close_connections(void) mysql_mutex_unlock(&LOCK_thread_count); #endif // Bug in BSDI kernel - /* All threads has now been aborted */ + /* + All threads have now been aborted. Stop event scheduler thread + after aborting all client connections, otherwise user may + start/stop event scheduler after Events::deinit() deallocates + scheduler object(static member in Events class) + */ + Events::deinit(); DBUG_PRINT("quit",("Waiting for threads to die (count=%u)", get_thread_count())); mysql_mutex_lock(&LOCK_thread_count); No bundle (reason: useless for push emails).