@@ -1147,6 +1147,7 @@ static PSI_mutex_key key_LOCK_rotate_binlog_master_key;
1147
1147
static PSI_mutex_key key_LOCK_partial_revokes;
1148
1148
static PSI_mutex_key key_LOCK_authentication_policy;
1149
1149
static PSI_mutex_key key_LOCK_global_conn_mem_limit;
1150
+ static PSI_rwlock_key key_rwlock_LOCK_server_shutting_down;
1150
1151
#endif /* HAVE_PSI_INTERFACE */
1151
1152
1152
1153
/**
@@ -1635,6 +1636,14 @@ mysql_mutex_t LOCK_authentication_policy;
1635
1636
1636
1637
mysql_mutex_t LOCK_global_conn_mem_limit;
1637
1638
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
+
1638
1647
bool mysqld_server_started = false;
1639
1648
/**
1640
1649
Set to true to signal at startup if the process must die.
@@ -1681,7 +1690,6 @@ bool binlog_expire_logs_seconds_supplied = false;
1681
1690
/* Static variables */
1682
1691
1683
1692
static bool opt_myisam_log;
1684
- static int cleanup_done;
1685
1693
static ulong opt_specialflag;
1686
1694
char *opt_binlog_index_name;
1687
1695
char *mysql_home_ptr, *pidfile_name_ptr;
@@ -2672,9 +2680,21 @@ static void free_connection_acceptors() {
2672
2680
#endif
2673
2681
}
2674
2682
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
+
2675
2694
static void clean_up(bool print_message) {
2676
2695
DBUG_PRINT("exit", ("clean_up"));
2677
- if (cleanup_done++) return; /* purecov: inspected */
2696
+
2697
+ if (set_server_shutting_down()) return;
2678
2698
2679
2699
unregister_pfs_metric_sources();
2680
2700
unregister_server_metric_sources();
@@ -2875,6 +2895,7 @@ static void clean_up_mutexes() {
2875
2895
mysql_mutex_destroy(&LOCK_partial_revokes);
2876
2896
mysql_mutex_destroy(&LOCK_authentication_policy);
2877
2897
mysql_mutex_destroy(&LOCK_global_conn_mem_limit);
2898
+ mysql_rwlock_destroy(&LOCK_server_shutting_down);
2878
2899
}
2879
2900
2880
2901
/****************************************************************************
@@ -3751,7 +3772,7 @@ extern "C" void *signal_hand(void *arg [[maybe_unused]]) {
3751
3772
"thread.",
3752
3773
errno);
3753
3774
3754
- if (error || cleanup_done ) {
3775
+ if (error || server_shutting_down ) {
3755
3776
my_thread_end();
3756
3777
my_thread_exit(nullptr); // Safety
3757
3778
return nullptr; // Avoid compiler warnings
@@ -7132,6 +7153,8 @@ static int init_thread_environment() {
7132
7153
MY_MUTEX_INIT_FAST);
7133
7154
mysql_mutex_init(key_LOCK_global_conn_mem_limit, &LOCK_global_conn_mem_limit,
7134
7155
MY_MUTEX_INIT_FAST);
7156
+ mysql_rwlock_init(key_rwlock_LOCK_server_shutting_down,
7157
+ &LOCK_server_shutting_down);
7135
7158
return 0;
7136
7159
}
7137
7160
@@ -11929,7 +11952,7 @@ static int mysql_init_variables() {
11929
11952
opt_tc_log_file = "tc.log"; // no hostname in tc_log file name !
11930
11953
opt_myisam_log = false;
11931
11954
mqh_used = false;
11932
- cleanup_done = 0 ;
11955
+ server_shutting_down = false ;
11933
11956
server_id_supplied = false;
11934
11957
test_flags = select_errors = ha_open_options = 0;
11935
11958
atomic_replica_open_temp_tables = 0;
@@ -13732,6 +13755,7 @@ static PSI_rwlock_info all_server_rwlocks[]=
13732
13755
{ &key_rwlock_rpl_filter_lock, "rpl_filter_lock", 0, 0, PSI_DOCUMENT_ME},
13733
13756
{ &key_rwlock_channel_to_filter_lock, "channel_to_filter_lock", 0, 0, PSI_DOCUMENT_ME},
13734
13757
{ &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."},
13735
13759
#ifdef _WIN32
13736
13760
{ &key_rwlock_LOCK_named_pipe_full_access_group, "LOCK_named_pipe_full_access_group", PSI_FLAG_SINGLETON, 0,
13737
13761
"This lock protects named pipe security attributes, preventing their "
0 commit comments