From 814dc46748d8c276f18c7664d8d14a543cff954c Mon Sep 17 00:00:00 2001 From: Monty Date: Sat, 27 Apr 2024 13:35:48 +0300 Subject: [PATCH] Fixed slow bootstrap introduced in 10.6 The problem was that the signal thread was not killed when using unireg_abort(). The bug was introduced by: MDEV-30260: Slave crashed:reload_acl_and_cache during shutdown Other things fixed: - Don't produce memory leaks with safemalloc if all threads was not ended properly (not useful) --- include/my_sys.h | 2 +- mysys/my_thr_init.c | 8 +++++--- sql/mysqld.cc | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index 84a1e6a4752..d58e53d0bf3 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -153,7 +153,7 @@ char *guess_malloc_library(); void sf_report_leaked_memory(my_thread_id id); int sf_sanity(); extern my_thread_id (*sf_malloc_dbug_id)(void); -#define SAFEMALLOC_REPORT_MEMORY(X) sf_report_leaked_memory(X) +#define SAFEMALLOC_REPORT_MEMORY(X) if (!sf_leaking_memory) sf_report_leaked_memory(X) #else #define SAFEMALLOC_REPORT_MEMORY(X) do {} while(0) #endif diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 2e8decd7d06..b2436d2be27 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -220,7 +220,11 @@ void my_thread_global_end(void) fprintf(stderr, "Error in my_thread_global_end(): %d threads didn't exit\n", THR_thread_count); -#endif +#endif /* HAVE_PTHREAD_KILL */ +#ifdef SAFEMALLOC + /* We know we will have memoryleaks, suppress the leak report */ + sf_leaking_memory= 1; +#endif /* SAFEMALLOC */ all_threads_killed= 0; break; } @@ -234,9 +238,7 @@ void my_thread_global_end(void) that could use them. */ if (all_threads_killed) - { my_thread_destroy_internal_mutex(); - } my_thread_global_init_done= 0; } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 0d2f1bd0309..6d7b09adc4c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1889,6 +1889,7 @@ extern "C" void unireg_abort(int exit_code) wsrep_sst_auth_free(); #endif // WITH_WSREP + wait_for_signal_thread_to_end(); clean_up(!opt_abort && (exit_code || !opt_bootstrap)); /* purecov: inspected */ DBUG_PRINT("quit",("done with cleanup in unireg_abort")); mysqld_exit(exit_code);