1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

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>
This commit is contained in:
Kristian Nielsen
2024-03-15 00:41:28 +01:00
parent 51e3f1daf5
commit 7f498fbab8

View File

@ -76,7 +76,9 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
pthread_detach_this_thread();
manager_thread = pthread_self();
mysql_mutex_lock(&LOCK_manager);
while (!abort_manager)
manager_thread_in_use = 1;
mysql_cond_signal(&COND_manager);
while (!abort_manager || cb_list)
{
/* XXX: This will need to be made more general to handle different
* polling needs. */
@ -116,6 +118,7 @@ pthread_handler_t handle_manager(void *arg __attribute__((unused)))
}
mysql_mutex_lock(&LOCK_manager);
}
DBUG_ASSERT(cb_list == NULL);
manager_thread_in_use = 0;
mysql_mutex_unlock(&LOCK_manager);
mysql_mutex_destroy(&LOCK_manager);
@ -135,12 +138,19 @@ void start_handle_manager()
pthread_t hThread;
int err;
DBUG_EXECUTE_IF("delay_start_handle_manager", my_sleep(1000););
manager_thread_in_use = 1;
mysql_cond_init(key_COND_manager, &COND_manager,NULL);
mysql_mutex_init(key_LOCK_manager, &LOCK_manager, NULL);
if ((err= mysql_thread_create(key_thread_handle_manager, &hThread,
&connection_attrib, handle_manager, 0)))
{
sql_print_warning("Can't create handle_manager thread (errno: %M)", err);
DBUG_VOID_RETURN;
}
mysql_mutex_lock(&LOCK_manager);
while (!manager_thread_in_use)
mysql_cond_wait(&COND_manager, &LOCK_manager);
mysql_mutex_unlock(&LOCK_manager);
}
DBUG_VOID_RETURN;
}