Skip to content

Commit 070919b

Browse files
committed
Bug#35854919 Client sessions not killed during shutdown, server seems stuck
During shutdown, killing connections or forcefully disconnecting them is done based on the THDs. However, running with the threadpool plugin may leave connections in a queue not yet handled by the thread group's conncection handling thread, when the server starts shutting down. Thus, the killing and forceful disconnect of the connections may be completed before the THD for the queued connection request is created, and hence, when the THD is eventually constructed, it will neither be killed nor forecfully disconnected, but still, the server will wait for the global connection count to be decremented, because the count was incremented when the request was received by the connection event loop. However, the counter will of course never be decremented as long as the client keeps the connection open. The suggested fix is to let the connection thread in each thread group just abandon unhandled connection requests when the server has aborted its connection event loop. Change-Id: I7c8d2ea4407a23d4486cbd46040846a576d67d81 (cherry picked from commit 43d55d944370b5da13b8b50743f6cf7e3f97b4fd)
1 parent 7b66063 commit 070919b

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

include/mysql/thread_pool_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ struct Connection_handler_functions {
7575
THD *create_thd(Channel_info *channel_info);
7676
/* destroy channel_info object */
7777
void destroy_channel_info(Channel_info *channel_info);
78+
/* Is the connection events loop aborted during shutdown. */
79+
bool connection_events_loop_aborted();
7880
/* Decrement connection counter */
7981
void dec_connection_count();
8082
/*

share/messages_to_error_log.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12289,6 +12289,12 @@ ER_GRP_RPL_MEMBER_INFO_DOES_NOT_EXIST
1228912289
ER_USAGE_DEPRECATION_COUNTER
1229012290
eng "Deprecated '%s' used %s times, last time used '%s'."
1229112291

12292+
ER_WAITING_FOR_NO_CONNECTIONS
12293+
eng "Waiting for %u connections to be closed."
12294+
12295+
ER_WAITING_FOR_NO_THDS
12296+
eng "Waiting for THDs in partition %u to be closed, %u still left. %u THDs left in total for all partitions."
12297+
1229212298
# DO NOT add server-to-client messages here;
1229312299
# they go in messages_to_clients.txt
1229412300
# in the same directory as this file.

sql/conn_handler/connection_handler_manager.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "mysql/components/services/bits/psi_bits.h"
3838
#include "mysql/components/services/bits/psi_cond_bits.h"
3939
#include "mysql/components/services/bits/psi_mutex_bits.h"
40+
#include "mysql/components/services/log_builtins.h"
4041
#include "mysql/service_thd_wait.h"
4142
#include "mysqld_error.h" // ER_*
4243
#include "sql/conn_handler/channel_info.h" // Channel_info
@@ -203,6 +204,7 @@ bool Connection_handler_manager::init() {
203204
void Connection_handler_manager::wait_till_no_connection() {
204205
mysql_mutex_lock(&LOCK_connection_count);
205206
while (connection_count > 0) {
207+
LogErr(INFORMATION_LEVEL, ER_WAITING_FOR_NO_CONNECTIONS, connection_count);
206208
mysql_cond_wait(&COND_connection_count, &LOCK_connection_count);
207209
}
208210
mysql_mutex_unlock(&LOCK_connection_count);

sql/mysqld_thd_manager.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "my_psi_config.h"
4747
#include "my_sys.h"
4848
#include "mysql/components/services/bits/psi_bits.h"
49+
#include "mysql/components/services/log_builtins.h"
4950
#include "mysql/thread_pool_priv.h" // inc_thread_created
5051
#include "sql/sql_class.h" // THD
5152
#include "thr_mutex.h"
@@ -278,6 +279,8 @@ void Global_THD_manager::wait_till_no_thd() {
278279
for (int i = 0; i < NUM_PARTITIONS; i++) {
279280
MUTEX_LOCK(lock, &LOCK_thd_list[i]);
280281
while (thd_list[i].size() > 0) {
282+
LogErr(INFORMATION_LEVEL, ER_WAITING_FOR_NO_THDS, i, thd_list[i].size(),
283+
get_thd_count());
281284
mysql_cond_wait(&COND_thd_list[i], &LOCK_thd_list[i]);
282285
DBUG_PRINT("quit", ("One thread died (count=%u)", get_thd_count()));
283286
}

0 commit comments

Comments
 (0)