Fix threadpool to report connections aborted due to wait timeout.

Update wait_timeout.test to add test case for this.
This commit is contained in:
Vladislav Vaintroub 2017-08-30 14:37:16 +00:00
parent d20fa48599
commit 91826970c5
8 changed files with 53 additions and 24 deletions

View file

@ -35,3 +35,9 @@ SELECT 3;
SET @@global.wait_timeout= <start_value>;
disconnect con1;
connect default,localhost,root,,test,,;
set global log_warnings=2;
connect foo,localhost,root;
set @@wait_timeout=1;
connection default;
FOUND 1 /Aborted.*Got timeout reading communication packets/ in mysqld.1.err
set global log_warnings=@@log_warnings;

View file

@ -1,6 +0,0 @@
set global log_warnings=2;
connect foo,localhost,root;
set @@wait_timeout=1;
connection default;
FOUND 1 /Aborted.*Got timeout reading communication packets/ in mysqld.1.err
set global log_warnings=@@log_warnings;

View file

@ -122,10 +122,22 @@ SELECT 3;
eval SET @@global.wait_timeout= $start_value;
disconnect con1;
# The last connect is to keep tools checking the current test happy.
connect (default,localhost,root,,test,,);
#
# MDEV-7775 Wrong error message (Unknown error) when idle sessions are killed after wait_timeout
#
set global log_warnings=2;
connect (foo,localhost,root);
set @@wait_timeout=1;
sleep 2;
connection default;
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err;
let SEARCH_PATTERN= Aborted.*Got timeout reading communication packets;
source include/search_pattern_in_file.inc;
set global log_warnings=@@log_warnings;
# Wait till all disconnects are completed
--source include/wait_until_count_sessions.inc

View file

@ -1,15 +0,0 @@
source include/not_embedded.inc;
source include/not_windows.inc;
#
# MDEV-7775 Wrong error message (Unknown error) when idle sessions are killed after wait_timeout
#
set global log_warnings=2;
connect (foo,localhost,root);
set @@wait_timeout=1;
sleep 2;
connection default;
let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err;
let SEARCH_PATTERN= Aborted.*Got timeout reading communication packets;
source include/search_pattern_in_file.inc;
set global log_warnings=@@log_warnings;

View file

@ -204,6 +204,10 @@ extern "C" sig_handler handle_fatal_signal(int sig)
case KILL_SLAVE_SAME_ID:
kreason= "KILL_SLAVE_SAME_ID";
break;
case KILL_WAIT_TIMEOUT:
case KILL_WAIT_TIMEOUT_HARD:
kreason= "KILL_WAIT_TIMEOUT";
break;
}
my_safe_printf_stderr("%s", "\n"
"Trying to get some variables.\n"

View file

@ -2008,6 +2008,9 @@ int THD::killed_errno()
DBUG_RETURN(ER_SERVER_SHUTDOWN);
case KILL_SLAVE_SAME_ID:
DBUG_RETURN(ER_SLAVE_SAME_ID);
case KILL_WAIT_TIMEOUT:
case KILL_WAIT_TIMEOUT_HARD:
DBUG_RETURN(ER_NET_READ_INTERRUPTED);
}
DBUG_RETURN(0); // Keep compiler happy
}

View file

@ -492,6 +492,11 @@ enum killed_state
KILL_SYSTEM_THREAD_HARD= 15,
KILL_SERVER= 16,
KILL_SERVER_HARD= 17,
/*
Used in threadpool to signal wait timeout.
*/
KILL_WAIT_TIMEOUT= 18,
KILL_WAIT_TIMEOUT_HARD= 19
};

View file

@ -308,6 +308,24 @@ static void threadpool_remove_connection(THD *thd)
my_thread_end();
}
/*
Ensure that proper error message is sent to client,
and "aborted" message appears in the log in case of
wait timeout.
See also timeout handling in net_serv.cc
*/
static void handle_wait_timeout(THD *thd)
{
thd->get_stmt_da()->reset_diagnostics_area();
thd->reset_killed();
my_error(ER_NET_READ_INTERRUPTED, MYF(0));
thd->net.last_errno= ER_NET_READ_INTERRUPTED;
thd->net.error= 2;
}
/**
Process a single client request or a single batch.
*/
@ -323,6 +341,8 @@ static int threadpool_process_request(THD *thd)
or KILL command. Return error.
*/
retval= 1;
if(thd->killed == KILL_WAIT_TIMEOUT)
handle_wait_timeout(thd);
goto end;
}
@ -458,7 +478,7 @@ void tp_timeout_handler(TP_connection *c)
return;
THD *thd=c->thd;
mysql_mutex_lock(&thd->LOCK_thd_data);
thd->killed= KILL_CONNECTION;
thd->set_killed(KILL_WAIT_TIMEOUT);
c->priority= TP_PRIORITY_HIGH;
post_kill_notification(thd);
mysql_mutex_unlock(&thd->LOCK_thd_data);