You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug#37780: Make KILL reliable (main.kill fails randomly)
- A prerequisite cleanup patch for making KILL reliable.
The test case main.kill did not work reliably.
The following problems have been identified:
1. A kill signal could go lost if it came in, short before a
thread went reading on the client connection.
2. A kill signal could go lost if it came in, short before a
thread went waiting on a condition variable.
These problems have been solved as follows. Please see also
added code comments for more details.
1. There is no safe way to detect, when a thread enters the
blocking state of a read(2) or recv(2) system call, where it
can be interrupted by a signal. Hence it is not possible to
wait for the right moment to send a kill signal. It has been
decided, not to fix it in the code. Instead, the test case
repeats the KILL statement until the connection terminates.
2. Before waiting on a condition variable, we register it
together with a synchronizating mutex in THD::mysys_var. After
this, we need to test THD::killed again. At some places we did
only test it in a loop condition before the registration. When
THD::killed had been set between this test and the registration,
we entered waiting without noticing the killed flag. Additional
checks ahve been introduced where required.
In addition to the above, a re-write of the main.kill test
case has been done. All sleeps have been replaced by Debug
Sync Facility synchronization. A couple of sync points have
been added to the server code.
To avoid further problems, if the test case fails in spite of
the fixes, the test case has been added to the "experimental"
list for now.
- Most of the work on this patch is authored by Ingo Struewing
INSERT t1 SELECT 0 FROM t1 AS a1, t1 AS a2 LIMIT 4032;
52
+
INSERT INTO t2 SELECT id FROM t1;
53
+
SET DEBUG_SYNC= 'thread_end SIGNAL con1_end';
54
+
SET DEBUG_SYNC= 'before_acos_function SIGNAL in_sync';
55
+
SELECT id FROM t1 WHERE id IN
56
+
(SELECT DISTINCT a.id FROM t2 a, t2 b, t2 c, t2 d
57
+
GROUP BY ACOS(1/a.id), b.id, c.id, d.id
58
+
HAVING a.id BETWEEN 10 AND 20);
59
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
60
+
KILL @id;
61
+
SET DEBUG_SYNC= 'now WAIT_FOR con1_end';
62
+
Got one of the listed errors
63
+
SELECT 1;
64
+
1
65
+
1
66
+
SET DEBUG_SYNC = 'RESET';
67
+
DROP TABLE t1, t2;
68
+
SET DEBUG_SYNC= 'before_acos_function SIGNAL in_sync WAIT_FOR kill';
69
+
SELECT ACOS(0);
70
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
71
+
KILL QUERY @id;
72
+
ACOS(0)
73
+
1.5707963267948966
74
+
SELECT 1;
75
+
1
76
+
1
77
+
SELECT @id = CONNECTION_ID();
78
+
@id = CONNECTION_ID()
79
+
1
80
+
SET DEBUG_SYNC = 'RESET';
81
+
CREATE TABLE t1 (f1 INT);
82
+
CREATE FUNCTION bug27563() RETURNS INT(11)
83
+
DETERMINISTIC
84
+
BEGIN
85
+
DECLARE CONTINUE HANDLER FOR SQLSTATE '70100' SET @a:= 'killed';
86
+
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception';
87
+
SET DEBUG_SYNC= 'now SIGNAL in_sync WAIT_FOR kill';
88
+
RETURN 1;
89
+
END|
90
+
INSERT INTO t1 VALUES (bug27563());
91
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
92
+
KILL QUERY @id;
93
+
ERROR 70100: Query execution was interrupted
94
+
SELECT * FROM t1;
64
95
f1
65
-
insert into t1 values(0);
66
-
update t1 set f1= bug27563();
96
+
SET DEBUG_SYNC = 'RESET';
97
+
INSERT INTO t1 VALUES(0);
98
+
UPDATE t1 SET f1= bug27563();
99
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
100
+
KILL QUERY @id;
67
101
ERROR 70100: Query execution was interrupted
68
-
select @a;
69
-
@a
70
-
NULL
71
-
select * from t1;
102
+
SELECT * FROM t1;
72
103
f1
73
104
0
74
-
insert into t1 values(1);
75
-
delete from t1 where bug27563() is null;
105
+
SET DEBUG_SYNC = 'RESET';
106
+
INSERT INTO t1 VALUES(1);
107
+
DELETE FROM t1 WHERE bug27563() IS NULL;
108
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
109
+
KILL QUERY @id;
76
110
ERROR 70100: Query execution was interrupted
77
-
select @a;
78
-
@a
79
-
NULL
80
-
select * from t1;
111
+
SELECT * FROM t1;
81
112
f1
82
113
0
83
114
1
84
-
select * from t1 where f1= bug27563();
85
-
ERROR 70100: Query execution was interrupted
86
-
select @a;
87
-
@a
88
-
NULL
89
-
create procedure proc27563()
90
-
begin
91
-
declare continue handler for sqlstate '70100' set @a:= 'killed';
92
-
declare continue handler for sqlexception set @a:= 'exception';
93
-
select get_lock("lock27563",10);
94
-
select "shouldn't be selected";
95
-
end|
96
-
call proc27563();
97
-
get_lock("lock27563",10)
98
-
NULL
99
-
ERROR 70100: Query execution was interrupted
100
-
select @a;
101
-
@a
102
-
NULL
103
-
create table t2 (f2 int);
104
-
create trigger trg27563 before insert on t1 for each row
105
-
begin
106
-
declare continue handler for sqlstate '70100' set @a:= 'killed';
107
-
declare continue handler for sqlexception set @a:= 'exception';
108
-
set @a:= get_lock("lock27563",10);
109
-
insert into t2 values(1);
110
-
end|
111
-
insert into t1 values(2),(3);
112
-
ERROR 70100: Query execution was interrupted
113
-
select @a;
114
-
@a
115
-
NULL
116
-
select * from t1;
115
+
SET DEBUG_SYNC = 'RESET';
116
+
SELECT * FROM t1 WHERE f1= bug27563();
117
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
118
+
KILL QUERY @id;
119
+
ERROR 70100: Query execution was interrupted
120
+
SELECT * FROM t1;
117
121
f1
118
122
0
119
123
1
120
-
select * from t2;
121
-
f2
122
-
select release_lock("lock27563");
123
-
release_lock("lock27563")
124
+
SET DEBUG_SYNC = 'RESET';
125
+
DROP FUNCTION bug27563;
126
+
CREATE TABLE t2 (f2 INT);
127
+
CREATE TRIGGER trg27563 BEFORE INSERT ON t1 FOR EACH ROW
128
+
BEGIN
129
+
DECLARE CONTINUE HANDLER FOR SQLSTATE '70100' SET @a:= 'killed';
130
+
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET @a:= 'exception';
131
+
INSERT INTO t2 VALUES(0);
132
+
SET DEBUG_SYNC= 'now SIGNAL in_sync WAIT_FOR kill';
133
+
INSERT INTO t2 VALUES(1);
134
+
END|
135
+
INSERT INTO t1 VALUES(2),(3);
136
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
137
+
KILL QUERY @id;
138
+
ERROR 70100: Query execution was interrupted
139
+
SELECT * FROM t1;
140
+
f1
141
+
0
124
142
1
125
-
drop table t1, t2;
126
-
drop function bug27563;
127
-
drop procedure proc27563;
143
+
SELECT * FROM t2;
144
+
f2
145
+
0
146
+
SET DEBUG_SYNC = 'RESET';
147
+
DROP TABLE t1, t2;
148
+
SET DEBUG_SYNC= 'before_join_optimize SIGNAL in_sync';
128
149
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 ';
129
150
EXECUTE stmt;
151
+
SET DEBUG_SYNC= 'now WAIT_FOR in_sync';
152
+
KILL QUERY @id;
153
+
ERROR 70100: Query execution was interrupted
154
+
SET DEBUG_SYNC = 'RESET';
130
155
#
131
156
# Bug#19723: kill of active connection yields different error code
132
157
# depending on platform.
133
158
#
134
159
135
-
# Connection: con2.
136
-
KILL CONNECTION_ID();
137
-
# CR_SERVER_LOST, CR_SERVER_GONE_ERROR, depending on the timing
0 commit comments