Bug #82679 Compound statements may silently eat KILL QUERY
Submitted: 22 Aug 2016 10:15 Modified: 22 Aug 2016 12:27
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.5.51, 5.6.33, 5.7.14 OS:Any
Assigned to: CPU Architecture:Any
Tags: compound statements, KILL

[22 Aug 2016 10:15] Laurynas Biveinis
Description:
KILL QUERY is ignored if it arrives after the compound statement-executing thread has sent EOF to the client for the previous substatement, and before it has started executing the next one.

How to repeat:
Apply (same patch for 5.5/5.6/5.7)

diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 7a61fc0..1f1e656 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -2737,6 +2737,7 @@ bool Query_result_send::send_eof()
     return TRUE;
   ::my_eof(thd);
   is_result_set_started= 0;
+  DEBUG_SYNC(thd, "sent_eof");
   return FALSE;
 }
 
Run MTR

delimiter |;
CREATE PROCEDURE sp()
WHILE TRUE DO
  SELECT 1;
END WHILE|
delimiter ;|

--connect(con1,localhost,root,,)

connection con1;

let $connection_id = `SELECT CONNECTION_ID()`;
SET DEBUG_SYNC="sent_eof SIGNAL sp_at_sent_eof WAIT_FOR sp_continue";
send CALL sp();

connection default;

SET DEBUG_SYNC="now WAIT_FOR sp_at_sent_eof";

--echo KILL query \$connection_id;
--disable_query_log
eval KILL QUERY $connection_id;
--enable_query_log

SET DEBUG_SYNC="now SIGNAL sp_continue";

connection con1;
--error ER_QUERY_INTERRUPTED
reap;
disconnect con1;

connection default;

DROP PROCEDURE sp;

It will ignore KILL and will continue executing CALL sp() indefinitely (until it aborts the query due to too large result set unconsumed by client)

If you comment out the three DEBUG_SYNC statements, the testcase is very unlikely to hit the bug-showing thread interleaving and completes very quickly.
[22 Aug 2016 10:17] Laurynas Biveinis
The testcase uses compound statement in a stored procedure. I have also seen this issue with a compound statement in an event definition.
[22 Aug 2016 12:27] MySQL Verification Team
Hello Laurynas,

Thank you for the report and test case.

Thanks,
Umesh
[22 Aug 2016 12:27] MySQL Verification Team
test results

Attachment: 82679.results (application/octet-stream, text), 37.42 KiB.