From bba4e7f28795be278816cb904cb2aaa5901fbb9b Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 22 Feb 2019 22:28:24 +0100 Subject: MDEV-18694 : Do not call close_connection() on active connections in server shutdown code. Fix fixes a race condition, if an active connection either writes, or will be writing to the socket after it is closed. Previous call to socket shutdown() is fully enough to wake up and idle connection, so that close_connection is obsolete and dangerous. --- sql/mysqld.cc | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b5c4a87d680..24993a045ac 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1562,27 +1562,12 @@ static my_bool kill_all_threads(THD *thd, void *) } -static my_bool kill_all_threads_once_again(THD *thd, void *) +static my_bool warn_threads_still_active(THD *thd, void *) { -#ifndef __bsdi__ // Bug in BSDI kernel - if (thd->vio_ok()) - { - if (global_system_variables.log_warnings) - sql_print_warning(ER_DEFAULT(ER_FORCING_CLOSE), my_progname, - (ulong) thd->thread_id, - (thd->main_security_ctx.user ? - thd->main_security_ctx.user : "")); - /* - close_connection() might need a valid current_thd - for memory allocation tracking. - */ - THD *save_thd= current_thd; - set_current_thd(thd); - close_connection(thd); - set_current_thd(save_thd); - } -#endif - + sql_print_warning("%s: Thread %llu (user : '%s') did not exit\n", my_progname, + (ulonglong) thd->thread_id, + (thd->main_security_ctx.user ? + thd->main_security_ctx.user : "")); return 0; } @@ -1735,12 +1720,8 @@ static void close_connections(void) for (int i= 0; thread_count && i < 1000; i++) my_sleep(20000); - /* - Force remaining threads to die by closing the connection to the client - This will ensure that threads that are waiting for a command from the - client on a blocking read call are aborted. - */ - server_threads.iterate(kill_all_threads_once_again); + if (global_system_variables.log_warnings) + server_threads.iterate(warn_threads_still_active); end_slave(); #ifdef WITH_WSREP -- cgit v1.2.1