Commit 91f00139 authored by unknown's avatar unknown

A patch for BUG#19723: kill of active connection yields

different error code depending on platform.

On Mac OS X, KILL statement issued to kill the current
connection would return a different error code and message than on
other platforms ('MySQL server has gone away' instead of 'Shutdown
in progress').

The reason for this difference was that on Mac OS X we have macro
SIGNAL_WITH_VIO_CLOSE defined. This macro forces KILL
implementation to close the communication socket of the thread
that is being killed. SIGNAL_WITH_VIO_CLOSE macro is defined on
platforms where just sending a signal is not a reliable mechanism
to interrupt the thread from sleeping on a blocking system call.
In a nutshell, closing the socket is a hack to work around an
operating system bug and awake the blocked thread no matter what.

However, if the thread that is being killed is the same
thread that issued KILL statement, closing the socket leads to a
prematurely lost connection. At the same time it is not necessary
to close the socket in this case, since the thread in question
is not inside a blocking system call.

The fix, therefore, is to not close the socket if the thread that
is being killed is the same that issued KILL statement, even with
defined SIGNAL_WITH_VIO_CLOSE.


mysql-test/r/kill.result:
  Update result file.
mysql-test/t/kill.test:
  Added a test case for BUG#19723: kill of active connection yields
  different error code depending on platform.
sql/sql_class.cc:
  Call close_active_vio() only if we're killing another thread.
parent 26b50304
......@@ -125,3 +125,12 @@ drop function bug27563;
drop procedure proc27563;
PREPARE stmt FROM 'EXPLAIN SELECT * FROM t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40 WHERE a1=a2 AND a2=a3 AND a3=a4 AND a4=a5 AND a5=a6 AND a6=a7 AND a7=a8 AND a8=a9 AND a9=a10 AND a10=a11 AND a11=a12 AND a12=a13 AND a13=a14 AND a14=a15 AND a15=a16 AND a16=a17 AND a17=a18 AND a18=a19 AND a19=a20 AND a20=a21 AND a21=a22 AND a22=a23 AND a23=a24 AND a24=a25 AND a25=a26 AND a26=a27 AND a27=a28 AND a28=a29 AND a29=a30 AND a30=a31 AND a31=a32 AND a32=a33 AND a33=a34 AND a34=a35 AND a35=a36 AND a36=a37 AND a37=a38 AND a38=a39 AND a39=a40 ';
EXECUTE stmt;
#
# Bug#19723: kill of active connection yields different error code
# depending on platform.
#
# Connection: con2.
KILL CONNECTION_ID();
SELECT 1;
ERROR HY000: Lost connection to MySQL server during query
......@@ -304,3 +304,19 @@ while ($i)
dec $i ;
}
--enable_query_log
###########################################################################
--echo #
--echo # Bug#19723: kill of active connection yields different error code
--echo # depending on platform.
--echo #
--echo
--echo # Connection: con2.
--connection con2
KILL CONNECTION_ID();
--error 2013
SELECT 1;
......@@ -818,7 +818,20 @@ void THD::awake(THD::killed_state state_to_set)
if (!slave_thread)
thread_scheduler.post_kill_notification(this);
#ifdef SIGNAL_WITH_VIO_CLOSE
close_active_vio();
if (this != current_thd)
{
/*
In addition to a signal, let's close the socket of the thread that
is being killed. This is to make sure it does not block if the
signal is lost. This needs to be done only on platforms where
signals are not a reliable interruption mechanism.
If we're killing ourselves, we know that we're not blocked, so this
hack is not used.
*/
close_active_vio();
}
#endif
}
if (mysys_var)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment