Skip to content

Commit

Permalink
Fix threadpool to report connections aborted due to wait timeout.
Browse files Browse the repository at this point in the history
Update wait_timeout.test to add test case for this.
  • Loading branch information
vaintroub committed Aug 30, 2017
1 parent d20fa48 commit 9182697
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 24 deletions.
6 changes: 6 additions & 0 deletions mysql-test/r/wait_timeout.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 0 additions & 6 deletions mysql-test/r/wait_timeout_not_windows.result

This file was deleted.

16 changes: 14 additions & 2 deletions mysql-test/t/wait_timeout.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

15 changes: 0 additions & 15 deletions mysql-test/t/wait_timeout_not_windows.test

This file was deleted.

4 changes: 4 additions & 0 deletions sql/signal_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions sql/sql_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

};

Expand Down
22 changes: 21 additions & 1 deletion sql/threadpool_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9182697

Please sign in to comment.