Skip to content

Commit 25b68d1

Browse files
committed
Bug#35721168 MDS: signal 11 during shutdown when audit log plugin is accessing tables
Scheduler component can execute its job during the server shutdown process. When it's accessing tables the open_and_lock_tables function call crashes the server. This fix disables call to the open_and_lock_tables when the server begins shutting down. Change-Id: I9584190a227f194da8fa2fa10c23104c26d82808
1 parent 81f9e27 commit 25b68d1

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Diff for: sql/mysqld.cc

+28-4
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ static PSI_mutex_key key_LOCK_rotate_binlog_master_key;
11471147
static PSI_mutex_key key_LOCK_partial_revokes;
11481148
static PSI_mutex_key key_LOCK_authentication_policy;
11491149
static PSI_mutex_key key_LOCK_global_conn_mem_limit;
1150+
static PSI_rwlock_key key_rwlock_LOCK_server_shutting_down;
11501151
#endif /* HAVE_PSI_INTERFACE */
11511152

11521153
/**
@@ -1635,6 +1636,14 @@ mysql_mutex_t LOCK_authentication_policy;
16351636

16361637
mysql_mutex_t LOCK_global_conn_mem_limit;
16371638

1639+
mysql_rwlock_t LOCK_server_shutting_down;
1640+
1641+
/*
1642+
Variable is reverted during shutdown command just before server's
1643+
internals are disabled.
1644+
*/
1645+
bool server_shutting_down = false;
1646+
16381647
bool mysqld_server_started = false;
16391648
/**
16401649
Set to true to signal at startup if the process must die.
@@ -1681,7 +1690,6 @@ bool binlog_expire_logs_seconds_supplied = false;
16811690
/* Static variables */
16821691

16831692
static bool opt_myisam_log;
1684-
static int cleanup_done;
16851693
static ulong opt_specialflag;
16861694
char *opt_binlog_index_name;
16871695
char *mysql_home_ptr, *pidfile_name_ptr;
@@ -2672,9 +2680,21 @@ static void free_connection_acceptors() {
26722680
#endif
26732681
}
26742682

2683+
static bool set_server_shutting_down() {
2684+
/* Server shutting down already set. */
2685+
if (server_shutting_down) return true;
2686+
2687+
mysql_rwlock_wrlock(&LOCK_server_shutting_down);
2688+
server_shutting_down = true;
2689+
mysql_rwlock_unlock(&LOCK_server_shutting_down);
2690+
2691+
return false;
2692+
}
2693+
26752694
static void clean_up(bool print_message) {
26762695
DBUG_PRINT("exit", ("clean_up"));
2677-
if (cleanup_done++) return; /* purecov: inspected */
2696+
2697+
if (set_server_shutting_down()) return;
26782698

26792699
unregister_pfs_metric_sources();
26802700
unregister_server_metric_sources();
@@ -2875,6 +2895,7 @@ static void clean_up_mutexes() {
28752895
mysql_mutex_destroy(&LOCK_partial_revokes);
28762896
mysql_mutex_destroy(&LOCK_authentication_policy);
28772897
mysql_mutex_destroy(&LOCK_global_conn_mem_limit);
2898+
mysql_rwlock_destroy(&LOCK_server_shutting_down);
28782899
}
28792900

28802901
/****************************************************************************
@@ -3751,7 +3772,7 @@ extern "C" void *signal_hand(void *arg [[maybe_unused]]) {
37513772
"thread.",
37523773
errno);
37533774

3754-
if (error || cleanup_done) {
3775+
if (error || server_shutting_down) {
37553776
my_thread_end();
37563777
my_thread_exit(nullptr); // Safety
37573778
return nullptr; // Avoid compiler warnings
@@ -7132,6 +7153,8 @@ static int init_thread_environment() {
71327153
MY_MUTEX_INIT_FAST);
71337154
mysql_mutex_init(key_LOCK_global_conn_mem_limit, &LOCK_global_conn_mem_limit,
71347155
MY_MUTEX_INIT_FAST);
7156+
mysql_rwlock_init(key_rwlock_LOCK_server_shutting_down,
7157+
&LOCK_server_shutting_down);
71357158
return 0;
71367159
}
71377160

@@ -11929,7 +11952,7 @@ static int mysql_init_variables() {
1192911952
opt_tc_log_file = "tc.log"; // no hostname in tc_log file name !
1193011953
opt_myisam_log = false;
1193111954
mqh_used = false;
11932-
cleanup_done = 0;
11955+
server_shutting_down = false;
1193311956
server_id_supplied = false;
1193411957
test_flags = select_errors = ha_open_options = 0;
1193511958
atomic_replica_open_temp_tables = 0;
@@ -13732,6 +13755,7 @@ static PSI_rwlock_info all_server_rwlocks[]=
1373213755
{ &key_rwlock_rpl_filter_lock, "rpl_filter_lock", 0, 0, PSI_DOCUMENT_ME},
1373313756
{ &key_rwlock_channel_to_filter_lock, "channel_to_filter_lock", 0, 0, PSI_DOCUMENT_ME},
1373413757
{ &key_rwlock_resource_group_mgr_map_lock, "Resource_group_mgr::m_map_rwlock", 0, 0, PSI_DOCUMENT_ME},
13758+
{ &key_rwlock_LOCK_server_shutting_down, "server_shutting_down", 0, 0, "This lock protects server shutting down flag."},
1373513759
#ifdef _WIN32
1373613760
{ &key_rwlock_LOCK_named_pipe_full_access_group, "LOCK_named_pipe_full_access_group", PSI_FLAG_SINGLETON, 0,
1373713761
"This lock protects named pipe security attributes, preventing their "

Diff for: sql/mysqld.h

+2
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ extern struct my_option my_long_early_options[];
380380
extern "C" MYSQL_PLUGIN_IMPORT bool mysqld_server_started;
381381
extern "C" MYSQL_PLUGIN_IMPORT int orig_argc;
382382
extern "C" MYSQL_PLUGIN_IMPORT char **orig_argv;
383+
extern bool server_shutting_down;
383384
extern my_thread_attr_t connection_attrib;
384385
extern bool old_mode;
385386
extern bool avoid_temporal_upgrade;
@@ -731,6 +732,7 @@ extern mysql_cond_t COND_manager;
731732
extern mysql_rwlock_t LOCK_sys_init_connect;
732733
extern mysql_rwlock_t LOCK_sys_init_replica;
733734
extern mysql_rwlock_t LOCK_system_variables_hash;
735+
extern mysql_rwlock_t LOCK_server_shutting_down;
734736

735737
extern ulong opt_ssl_fips_mode;
736738

Diff for: sql/server_component/table_access_service.cc

+11
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,17 @@ size_t Table_access_impl::add_table(const char *schema_name,
739739
}
740740

741741
int Table_access_impl::begin() {
742+
/*
743+
Read lock must be acquired during entire open_and_lock_tables function
744+
call, because shutdown process can make its internals unavailable in the
745+
middle of the call. If tables are acquired before the shutdown process, the
746+
shutdown process will not deallocate internals until tables are closed.
747+
*/
748+
rwlock_scoped_lock rdlock(&LOCK_server_shutting_down, false, __FILE__,
749+
__LINE__);
750+
751+
if (server_shutting_down) return TA_ERROR_OPEN;
752+
742753
if (m_write && m_parent_thd != nullptr) {
743754
if (m_parent_thd->global_read_lock.is_acquired()) {
744755
/*

0 commit comments

Comments
 (0)