From 550d6871a5eb93013435055e11a4fe3009490c82 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 3 May 2012 02:47:06 +0200 Subject: [PATCH] MDEV-246 - Aborted_clients incremented during ordinary connection close The problem was increment of aborted_threads variable due to thd->killed which was set when threadpool connection was terminated . The fix is not to set thd->killed anymore, there is no real reason for doing it.. Added a test that checks that status variable aborted_clients does not grow for ordinary disconnects, and that successful KILL increments this variable. --- mysql-test/r/aborted_clients.result | 10 ++++++++++ mysql-test/t/aborted_clients.test | 26 ++++++++++++++++++++++++++ sql/threadpool_common.cc | 1 - sql/threadpool_win.cc | 4 ++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 mysql-test/r/aborted_clients.result create mode 100644 mysql-test/t/aborted_clients.test diff --git a/mysql-test/r/aborted_clients.result b/mysql-test/r/aborted_clients.result new file mode 100644 index 00000000000..7111a0c98db --- /dev/null +++ b/mysql-test/r/aborted_clients.result @@ -0,0 +1,10 @@ +FLUSH STATUS; +SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME='aborted_clients'; +VARIABLE_VALUE +0 +KILL CONNECTION_ID(); +ERROR 70100: Connection was killed +SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME='aborted_clients'; +VARIABLE_VALUE +1 +FLUSH STATUS; diff --git a/mysql-test/t/aborted_clients.test b/mysql-test/t/aborted_clients.test new file mode 100644 index 00000000000..aa278554c8f --- /dev/null +++ b/mysql-test/t/aborted_clients.test @@ -0,0 +1,26 @@ +# Test case for MDEV-246, lp:992983 +# Check that ordinary connect/disconnect does not increase aborted_clients +# status variable, but KILL connection does + +-- source include/not_embedded.inc + +FLUSH STATUS; +# Connect/Disconnect look that aborted_clients stays 0 +connect (con1,localhost,root,,); +disconnect con1; +connection default; +# Check that there is 0 aborted clients so far +SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME='aborted_clients'; + +# Kill a connection, check that aborted_clients is incremented +connect(con2,localhost,root,,); +--disable_reconnect +--error ER_CONNECTION_KILLED +KILL CONNECTION_ID(); +disconnect con2; +connection default; + +# aborted clients must be 1 now +SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME='aborted_clients'; +FLUSH STATUS; + diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc index 03ccb3fa861..7e5bbd11c69 100644 --- a/sql/threadpool_common.cc +++ b/sql/threadpool_common.cc @@ -167,7 +167,6 @@ void threadpool_remove_connection(THD *thd) worker_context.save(); thread_attach(thd); - thd->killed= KILL_CONNECTION; thd->net.reading_or_writing= 0; end_connection(thd); diff --git a/sql/threadpool_win.cc b/sql/threadpool_win.cc index c8cc38e612a..6359f81cd2b 100644 --- a/sql/threadpool_win.cc +++ b/sql/threadpool_win.cc @@ -573,6 +573,10 @@ static VOID CALLBACK io_completion_callback(PTP_CALLBACK_INSTANCE instance, } connection_t *connection = (connection_t*)context; + + if (io_result != ERROR_SUCCESS) + goto error; + THD *thd= connection->thd; ulonglong old_timeout = connection->timeout; connection->timeout = ULONGLONG_MAX;