Bug #111686 Contribution by Tencent: shutdown takes at least 8 seconds if have slave
Submitted: 7 Jul 2023 1:57 Modified: 7 Jul 2023 6:31
Reporter: yewei Xu (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S5 (Performance)
Version:5.7,8.0, 5.7.42 OS:Any
Assigned to: CPU Architecture:Any

[7 Jul 2023 1:57] yewei Xu
Description:
In function close_connections, dump_thread_kill_retries hardcoded to 8, 
dump_thread_count has not been assigned after initialized to 0. So
thd_manager->get_thd_count() always bigger than dump_thread_count if have slave
instance. mysql shutdown will takes at least 8 seconds.

How to repeat:
read the code,
shutdown mysqld with replication slave.

Suggested fix:
assign dump_thread_count with right value

diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 90c2050ef66..c636198d854 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -2330,7 +2330,7 @@ static void close_connections(void) {
   LogErr(INFORMATION_LEVEL, ER_SHUTTING_DOWN_REPLICA_THREADS);
   end_slave();
 
-  if (set_kill_conn.get_dump_thread_count()) {
+  if (dump_thread_count = set_kill_conn.get_dump_thread_count()) {
     /*
       Replication dump thread should be terminated after the clients are
       terminated. Wait for few more seconds for other sessions to end.
[7 Jul 2023 6:31] MySQL Verification Team
Hello  Yewei Xu,

Thank you for the report and contribution.
Verified as described.

regards,
Umesh