Bug #105318 we will waste 8 seconds to wait mysql shutdown every time
Submitted: 26 Oct 2021 8:01 Modified: 27 Oct 2021 8:10
Reporter: xiaoyang qian Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:5.7.36, 8.0 OS:Any
Assigned to: CPU Architecture:Any

[26 Oct 2021 8:01] xiaoyang qian
Description:
In close_connections function, the variable dump_thread_count defined to zero, but never be modified.

Cause when we shutdown mysql, we will ALWAYS waste 8 seconds to wait to shutdown.

It happens in all mysql version, include 5.7 and 8.0.

Bug at https://github.com/mysql/mysql-server/blob/5.7/sql/mysqld.cc#L1060

How to repeat:
Execute `shutdown` command in mysql which has at least one slave.

U can see this in log, mysqld stops dump thread after waiting 8 seconds (from 16:03:00.485118 to 16:03:08.485666).

2021-10-21T16:03:00.485035+08:00 0 [Note] Giving 103 client threads a chance to die gracefully
2021-10-21T16:03:00.485118+08:00 0 [Note] Shutting down slave threads
2021-10-21T16:03:08.485666+08:00 6 [Note] Stop semi-sync binlog_dump to slave (server_id: 10119406)

Suggested fix:
fix code bug.
[26 Oct 2021 8:14] xiaoyang qian
fix:

--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -1041,7 +1041,7 @@ static void close_connections(void)
   sql_print_information("Shutting down slave 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
[27 Oct 2021 8:10] MySQL Verification Team
Hello xiaoyang qian,

Thank you for the report and feedback.
Verified as described with 5.7.36 build.

regards,
Umesh