Skip to content

Commit 7f498fb

Browse files
committed
Fix "Assertion `THR_PFS_initialized' failed" in main.bootstrap
This patch makes the server wait for the manager thread to actually start before proceeding with server startup. Without this, if thread scheduling is really slow and the server shutdowns quickly, then it is possible that the manager thread is not yet started when shutdown_performance_schema() is called. If the manager thread starts at just the wrong moment and just before the main server reaches exit(), the thread can try to access no longer available performance schema data. This was seen as occasional assertion in the main.bootstrap test. As an additional improvement, make sure to run all pending actions before exiting the manager thread. Reviewed-by: Monty <monty@mariadb.org> Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
1 parent 51e3f1d commit 7f498fb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sql/sql_manager.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
7676
pthread_detach_this_thread();
7777
manager_thread = pthread_self();
7878
mysql_mutex_lock(&LOCK_manager);
79-
while (!abort_manager)
79+
manager_thread_in_use = 1;
80+
mysql_cond_signal(&COND_manager);
81+
while (!abort_manager || cb_list)
8082
{
8183
/* XXX: This will need to be made more general to handle different
8284
* polling needs. */
@@ -116,6 +118,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
116118
}
117119
mysql_mutex_lock(&LOCK_manager);
118120
}
121+
DBUG_ASSERT(cb_list == NULL);
119122
manager_thread_in_use = 0;
120123
mysql_mutex_unlock(&LOCK_manager);
121124
mysql_mutex_destroy(&LOCK_manager);
@@ -135,12 +138,19 @@ void start_handle_manager()
135138
pthread_t hThread;
136139
int err;
137140
DBUG_EXECUTE_IF("delay_start_handle_manager", my_sleep(1000););
138-
manager_thread_in_use = 1;
139141
mysql_cond_init(key_COND_manager, &COND_manager,NULL);
140142
mysql_mutex_init(key_LOCK_manager, &LOCK_manager, NULL);
141143
if ((err= mysql_thread_create(key_thread_handle_manager, &hThread,
142144
&connection_attrib, handle_manager, 0)))
145+
{
143146
sql_print_warning("Can't create handle_manager thread (errno: %M)", err);
147+
DBUG_VOID_RETURN;
148+
}
149+
150+
mysql_mutex_lock(&LOCK_manager);
151+
while (!manager_thread_in_use)
152+
mysql_cond_wait(&COND_manager, &LOCK_manager);
153+
mysql_mutex_unlock(&LOCK_manager);
144154
}
145155
DBUG_VOID_RETURN;
146156
}

0 commit comments

Comments
 (0)