MySQL Bug#74846 Index: mysql-5.7.5-m15/plugin/semisync/semisync_master.cc =================================================================== --- mysql-5.7.5-m15.orig/plugin/semisync/semisync_master.cc +++ mysql-5.7.5-m15/plugin/semisync/semisync_master.cc @@ -556,9 +556,9 @@ void ReplSemiSyncMaster::remove_slave() */ if ((rpl_semi_sync_master_clients == rpl_semi_sync_master_wait_for_slave_count - 1) && - (!rpl_semi_sync_master_wait_no_slave || abort_loop)) + (!rpl_semi_sync_master_wait_no_slave || in_abort_loop())) { - if (abort_loop) + if (in_abort_loop()) { if (commit_file_name_inited_ && reply_file_name_inited_) { @@ -785,7 +785,7 @@ int ReplSemiSyncMaster::commitTrx(const * when replication has progressed far enough, we will release * these waiting threads. */ - if (abort_loop && (rpl_semi_sync_master_clients == + if (in_abort_loop() && (rpl_semi_sync_master_clients == rpl_semi_sync_master_wait_for_slave_count - 1) && is_on()) { sql_print_warning("SEMISYNC: Forced shutdown. Some updates might " Index: mysql-5.7.5-m15/sql/conn_handler/connection_acceptor.h =================================================================== --- mysql-5.7.5-m15.orig/sql/conn_handler/connection_acceptor.h +++ mysql-5.7.5-m15/sql/conn_handler/connection_acceptor.h @@ -62,7 +62,7 @@ public: void connection_event_loop() { Connection_handler_manager *mgr= Connection_handler_manager::get_instance(); - while (!abort_loop) + while (!in_abort_loop()) { Channel_info *channel_info= m_listener->listen_for_connection_event(); if (channel_info != NULL) Index: mysql-5.7.5-m15/sql/conn_handler/connection_handler_manager.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/conn_handler/connection_handler_manager.cc +++ mysql-5.7.5-m15/sql/conn_handler/connection_handler_manager.cc @@ -235,7 +235,7 @@ bool Connection_handler_manager::unload_ void Connection_handler_manager::process_new_connection(Channel_info* channel_info) { - if (abort_loop || !check_and_incr_conn_count()) + if (in_abort_loop() || !check_and_incr_conn_count()) { channel_info->send_error_and_close_channel(ER_CON_COUNT_ERROR, 0, true); delete channel_info; Index: mysql-5.7.5-m15/sql/conn_handler/named_pipe_connection.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/conn_handler/named_pipe_connection.cc +++ mysql-5.7.5-m15/sql/conn_handler/named_pipe_connection.cc @@ -114,7 +114,7 @@ Channel_info* Named_pipe_listener::liste fConnected= GetOverlappedResult(m_pipe_handle, &m_connect_overlapped, &bytes, TRUE); } - if (abort_loop) + if (in_abort_loop()) return NULL; if (!fConnected) fConnected = GetLastError() == ERROR_PIPE_CONNECTED; Index: mysql-5.7.5-m15/sql/conn_handler/shared_memory_connection.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/conn_handler/shared_memory_connection.cc +++ mysql-5.7.5-m15/sql/conn_handler/shared_memory_connection.cc @@ -217,7 +217,7 @@ Channel_info* Shared_mem_listener::liste /* it can be after shutdown command */ - if (abort_loop) + if (in_abort_loop()) return NULL; char connect_number_char[22]; @@ -288,7 +288,7 @@ Channel_info* Shared_mem_listener::liste errmsg= "Could not create closed connection event"; goto errorconn; } - if (abort_loop) + if (in_abort_loop()) goto errorconn; Channel_info* channel_info= new (std::nothrow) Index: mysql-5.7.5-m15/sql/conn_handler/socket_connection.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/conn_handler/socket_connection.cc +++ mysql-5.7.5-m15/sql/conn_handler/socket_connection.cc @@ -855,11 +855,11 @@ Channel_info* Mysqld_socket_listener::li increment the server global status variable. */ connection_errors_select++; - if (!select_errors++ && !abort_loop) + if (!select_errors++ && !in_abort_loop()) sql_print_error("mysqld: Got error %d from select",socket_errno); } - if (retval < 0 || abort_loop) + if (retval < 0 || in_abort_loop()) return NULL; Index: mysql-5.7.5-m15/sql/filesort.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/filesort.cc +++ mysql-5.7.5-m15/sql/filesort.cc @@ -498,7 +498,8 @@ ha_rows filesort(THD *thd, QEP_TAB *qep_ to client! */ const char *cause= kill_errno - ? ((kill_errno == THD::KILL_CONNECTION && !abort_loop) + ? ((kill_errno == THD::KILL_CONNECTION + && !in_abort_loop()) ? ER(THD::KILL_QUERY) : ER(kill_errno)) : thd->get_stmt_da()->message_text(); Index: mysql-5.7.5-m15/sql/init.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/init.cc +++ mysql-5.7.5-m15/sql/init.cc @@ -24,7 +24,7 @@ #include "sql_priv.h" #include "init.h" #include "my_sys.h" -#include "mysqld.h" // abort_loop, ... +#include "mysqld.h" // in_abort_loop(), ... #include "my_time.h" // my_init_time #include "unireg.h" // SPECIAL_SAME_DB_NAME #include @@ -38,7 +38,7 @@ void unireg_init(ulong options) DBUG_ENTER("unireg_init"); error_handler_hook = my_message_stderr; - abort_loop=0; + set_in_abort_loop(false); wild_many='%'; wild_one='_'; wild_prefix='\\'; /* Change to sql syntax */ Index: mysql-5.7.5-m15/sql/log.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/log.cc +++ mysql-5.7.5-m15/sql/log.cc @@ -1892,7 +1892,7 @@ void error_log_print(enum loglevel level if (log_syslog_enabled #ifdef _WIN32 - && !abort_loop // Don't write to the eventlog during shutdown. + && !in_abort_loop() // Don't write to the eventlog during shutdown. #endif ) { Index: mysql-5.7.5-m15/sql/mysqld.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/mysqld.cc +++ mysql-5.7.5-m15/sql/mysqld.cc @@ -293,7 +293,7 @@ bool server_id_supplied = false; bool opt_endinfo, using_udf_functions; my_bool locked_in_memory; bool opt_using_transactions; -bool volatile abort_loop; +bool _in_abort_loop; ulong log_warnings; bool opt_log_syslog_enable; char *opt_log_syslog_tag= NULL; @@ -2193,10 +2193,11 @@ pthread_handler_t signal_hand(void *arg // Switch to the file log message processing. query_logger.set_handlers((log_output_options != LOG_NONE) ? LOG_FILE : LOG_NONE); - DBUG_PRINT("info", ("Got signal: %d abort_loop: %d", sig, abort_loop)); - if (!abort_loop) + DBUG_PRINT("info", ("Got signal: %d abort_loop: %d", + sig, in_abort_loop())); + if (!in_abort_loop()) { - abort_loop= true; // Mark abort for threads. + set_in_abort_loop(true); // Mark abort for threads. #ifdef HAVE_PSI_THREAD_INTERFACE // Delete the instrumentation for the signal thread. PSI_THREAD_CALL(delete_current_thread)(); @@ -2227,7 +2228,7 @@ pthread_handler_t signal_hand(void *arg } break; case SIGHUP: - if (!abort_loop) + if (!in_abort_loop()) { int not_used; mysql_print_status(); // Print some debug info @@ -4126,7 +4127,7 @@ pthread_handler_t handle_shutdown(void * if (WaitForSingleObject(hEventShutdown,INFINITE)==WAIT_OBJECT_0) { sql_print_information(ER_DEFAULT(ER_NORMAL_SHUTDOWN), my_progname); - abort_loop= true; + set_in_abort_loop(true); close_connections(); my_thread_end(); pthread_exit(0); @@ -4635,7 +4636,7 @@ int mysqld_main(int argc, char **argv) if (mysql_rm_tmp_tables() || acl_init(opt_noacl) || my_tz_init((THD *)0, default_tz_name, opt_bootstrap)) { - abort_loop= true; + set_in_abort_loop(true); (void) pthread_kill(signal_thread_id, SIGTERM); @@ -6563,7 +6564,7 @@ static int mysql_init_variables(void) slave_open_temp_tables= 0; opt_endinfo= using_udf_functions= 0; opt_using_transactions= 0; - abort_loop= false; + set_in_abort_loop(false); grant_option= 0; aborted_threads= 0; delayed_insert_threads= delayed_insert_writes= delayed_rows_in_use= 0; Index: mysql-5.7.5-m15/sql/mysqld.h =================================================================== --- mysql-5.7.5-m15.orig/sql/mysqld.h +++ mysql-5.7.5-m15/sql/mysqld.h @@ -118,7 +118,17 @@ extern bool opt_disable_networking, opt_ extern bool opt_skip_name_resolve; extern bool opt_ignore_builtin_innodb; extern my_bool opt_character_set_client_handshake; -extern MYSQL_PLUGIN_IMPORT bool volatile abort_loop; +extern MYSQL_PLUGIN_IMPORT int32 _in_abort_loop; /* use accessor function! */ +inline __attribute__((warn_unused_result)) bool in_abort_loop() +{ + return my_atomic_load32(&_in_abort_loop); +} +/* only here because of unireg_init(). */ +static inline void set_in_abort_loop(bool value) +{ + my_atomic_store32(&_in_abort_loop, value); +} + extern my_bool opt_bootstrap; extern my_bool opt_safe_user_create; extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap; Index: mysql-5.7.5-m15/sql/rpl_gtid_execution.cc =================================================================== --- mysql-5.7.5-m15.orig/sql/rpl_gtid_execution.cc +++ mysql-5.7.5-m15/sql/rpl_gtid_execution.cc @@ -78,7 +78,7 @@ int gtid_acquire_ownership_single(THD *t // global_sid_lock and mutex are now released // Check if thread was killed. - if (thd->killed || abort_loop) + if (thd->killed || in_abort_loop()) DBUG_RETURN(1); #ifdef HAVE_REPLICATION // If this thread is a slave SQL thread or slave SQL worker @@ -168,7 +168,7 @@ int gtid_acquire_ownership_multiple(THD // at this point, we don't hold any locks. re-acquire the global // read lock that was held when this function was invoked - if (thd->killed || abort_loop) + if (thd->killed || in_abort_loop()) DBUG_RETURN(1); #ifdef HAVE_REPLICATION // If this thread is a slave SQL thread or slave SQL worker Index: mysql-5.7.5-m15/sql/rpl_slave.h =================================================================== --- mysql-5.7.5-m15.orig/sql/rpl_slave.h +++ mysql-5.7.5-m15/sql/rpl_slave.h @@ -355,7 +355,6 @@ pthread_handler_t handle_slave_io(void * pthread_handler_t handle_slave_sql(void *arg); bool net_request_file(NET* net, const char* fname); -extern bool volatile abort_loop; extern Master_info *active_mi; /* active_mi for multi-master */ extern LIST master_list; extern my_bool replicate_same_server_id; Index: mysql-5.7.5-m15/sql/sql_class.h =================================================================== --- mysql-5.7.5-m15.orig/sql/sql_class.h +++ mysql-5.7.5-m15/sql/sql_class.h @@ -3199,7 +3199,7 @@ public: int err= killed_errno(); if (err && !get_stmt_da()->is_set()) { - if ((err == KILL_CONNECTION) && !abort_loop) + if ((err == KILL_CONNECTION) && !in_abort_loop()) err = KILL_QUERY; /* KILL is fatal because: