Debian Codegraph @

mysql-test/suite/x/t/client_close.test

raw
1 ## Test various client close/dispose scenarios
2
3 # // client just disconnected on us
4 # Close_peer_disconnected,
5 # // client sent a close command
6 # Close_requested_by_client,
7 # // server is shutting down
8 # Close_server_shutdown,
9 # // client was killed (as in via SQL KILL command by another client)
10 # Close_client_killed,
11 # // unrecoverable network error occurred
12 # Close_net_error,
13 # // a fatal application error occurred
14 # Close_fatal_error,
15 # // like Client_fatal_error, except that error is not reported to the client
16 # Close_aborted
17
18 --source include/restart_mysqld.inc
19 --source include/xplugin_preamble.inc
20 --source include/xplugin_create_user.inc
21
22 call mtr.add_suppression('Message of size 4294967040 received, exceeding the limit of 1048576');
23 # Plugin 'InnoDB' has ref_count=1 after shutdown
24 call mtr.add_suppression("Plugin \'InnoDB\'");
25 # wait a little to give time for internal temporary session to die out
26 select sleep(1);
27 --replace_regex /localhost[:0-9]*/localhost/ /Execute/Query/
28 SELECT `user`,`host`,`db`,`command`,`state`,`info` FROM INFORMATION_SCHEMA.PROCESSLIST WHERE `state` != 'cleaning up' ORDER BY user ASC;
29
30 ## Test starts here
31 --write_file $MYSQL_TMP_DIR/client_close.xpl
32 -->import assert_status_variable.macro
33 -->import connection.macro
34 # number of seconds to sleep... increase to a higher value once killing sessions on disconnect works
35 -->varlet %SLEEP% 2
36
37 -->macro Close_active_and_sync
38 Mysqlx.Connection.Close {
39 }
40 -->recvtype Mysqlx.Ok
41 -->peerdisc 1000 5000
42 -->endmacro
43
44
45 -->sql
46 delimiter //;
47 create procedure test.get_stuck()
48 begin
49 declare i int;
50 declare x int;
51 set i = 1;
52 while i < 1000 do
53 set i = i + 1;
54 set x = sleep(0.5);
55 end while;
56 end//;
57 delimiter ;
58
59 show global status like 'mysqlx_connections_%';
60 -->endsql
61
62 -->title #Close_peer_disconnected
63 -->title -Connect and disconnect while idle
64 -->newsession sess x_root
65 -->closesession abort
66
67 -->sql
68 select sleep(%SLEEP%);
69 show global status like 'mysqlx_connections_%';
70 -->endsql
71
72 ##########
73
74 -->title -Connect and disconnect while running a query
75 -->newsession sess x_root
76
77 Mysqlx.Sql.StmtExecute {
78 stmt: "select sleep(%SLEEP%)"
79 }
80
81 # read the resultset metadata, which is sent immediately
82 -->recv
83
84 -->closesession abort
85 -->callmacro Wait_for_global_status_variable mysqlx_connections_closed 2
86 -->sql
87 show global status like 'mysqlx_connections_%';
88 -->endsql
89
90 ##########
91
92 -->title -Connect and disconnect while streaming result
93 -->newsession sess x_root
94
95 Mysqlx.Sql.StmtExecute {
96 stmt: "show variables"
97 }
98
99 -->closesession abort
100
101 -->callmacro Wait_for_global_status_variable mysqlx_connections_closed 3
102
103 -->sql
104 show global status like 'mysqlx_connections_%';
105 -->endsql
106
107 ###########
108
109 -->title -Connect and disconnect while input queue is full
110 -->newsession sess x_root
111
112 Mysqlx.Sql.StmtExecute {
113 stmt: "select sleep(%SLEEP%)"
114 }
115 Mysqlx.Sql.StmtExecute {
116 stmt: "select 1"
117 }
118
119 -->closesession abort
120 -->callmacro Wait_for_global_status_variable mysqlx_connections_closed 4
121
122 -->sql
123 show global status like 'mysqlx_connections_%';
124 -->endsql
125
126 -->title -Disconnect while in a pipeline
127
128 -->newsession sess x_root
129 Mysqlx.Sql.StmtExecute {
130 stmt: "select 6"
131 }
132 Mysqlx.Sql.StmtExecute {
133 stmt: "select 1"
134 }
135 -->recv
136 -->closesession abort
137
138
139 ############
140 -->title #Close_requested_by_client
141
142 -->title -Close when idle
143
144 -->newsession sess x_root
145 Mysqlx.Sql.StmtExecute {
146 stmt: "select 1"
147 }
148 -->recvresult
149 -->callmacro Close_active_and_sync
150
151 -->sql
152 select sleep(%SLEEP%);
153 show global status like 'mysqlx_connections_%';
154 -->endsql
155
156 -->title -Close in a pipeline
157
158 -->newsession sess x_root
159 Mysqlx.Sql.StmtExecute {
160 stmt: "select 2"
161 }
162 Mysqlx.Sql.StmtExecute {
163 stmt: "select 3"
164 }
165 Mysqlx.Connection.Close {
166 }
167 # ALL results up to the Close must be readable by client
168 -->recvresult
169 -->recvresult
170 -->recvok
171 -->expecterror CR_SERVER_GONE_ERROR
172 -->sleep 1
173 -->sql
174 select 4;
175 -->endsql
176
177 # "abort", since we already sent the close
178 -->closesession abort
179
180 -->title #Close_client_killed
181
182 -->title -Kill a session while idle
183
184 -->newsession sess x_root
185 -->varlet %SESS_CLIENT_ID% %ACTIVE_CLIENT_ID%
186 -->setsession
187 -->stmtadmin kill_client {"id": %SESS_CLIENT_ID% }
188 # The kill operation can return an error here. If the thread being killed is in "kill immune" mode
189 # its killing is delayed till it leaves that mode. This is temporary solution in the server for the DD opartions.
190 # The kill immune mode is to be removed in the future.
191 -->expecterror 0, 1095
192 -->recvresult be-quiet
193
194 -->setsession sess
195 -->closesession abort
196
197 # Due to race condition on the 'vio' level, we need some small delay
198 # between tests. The 'valgrind' is a kind of catalyst and makes this
199 # issue more probably. Bug#31593665 has been reported.
200 -->sleep 1
201
202 -->title -Kill a session executing query
203
204 -->newsession sess x_root
205 -->varlet %SESS_CLIENT_ID% %ACTIVE_CLIENT_ID%
206 Mysqlx.Sql.StmtExecute {
207 stmt: "call test.get_stuck()"
208 }
209 Mysqlx.Sql.StmtExecute {
210 stmt: "select 1"
211 }
212
213 -->setsession
214 -->stmtadmin kill_client {"id": %SESS_CLIENT_ID% }
215 # The kill operation can return an error here. If the thread being killed is in "kill immune" mode
216 # its killing is delayed till it leaves that mode. This is temporary solution in the server for the DD opartions.
217 # The kill immune mode is to be removed in the future.
218 -->expecterror 0, 1095
219 -->recvresult be-quiet
220
221 -->setsession sess
222
223 -->expecterror 1317,2006,2007,5010
224 -->recvresult
225
226 -->closesession abort
227
228 -->title -Kill a session that hasnt authenticated yet
229
230 -->newsession sess -
231 -->callmacro Verify_its_xprotocol_connection
232 -->varlet %SESS_CLIENT_ID% 11
233
234 -->sleep 1
235
236 -->setsession
237 -->stmtadmin kill_client {"id": %SESS_CLIENT_ID% }
238 # The kill operation can return an error here. If the thread being killed is in "kill immune" mode
239 # its killing is delayed till it leaves that mode. This is temporary solution in the server for the DD opartions.
240 # The kill immune mode is to be removed in the future.
241 -->expecterror 0, 1095
242 -->recvresult be-quiet
243
244 -->setsession sess
245 -->expecterror 2006,2007
246 -->sql
247 select 1;
248 -->endsql
249
250 -->closesession abort
251
252 -->title -Kill a session that hasnt authenticated yet, with data queued
253
254 -->newsession sess -
255 -->callmacro Verify_its_xprotocol_connection
256 -->varlet %SESS_CLIENT_ID% 12
257
258 -->sleep 1
259
260 Mysqlx.Connection.CapabilitiesGet {
261 }
262
263 -->setsession
264 -->stmtadmin kill_client {"id": %SESS_CLIENT_ID% }
265 # The kill operation can return an error here. If the thread being killed is in "kill immune" mode
266 # its killing is delayed till it leaves that mode. This is temporary solution in the server for the DD opartions.
267 # The kill immune mode is to be removed in the future.
268 -->expecterror 0, 1095
269 -->recvresult be-quiet
270
271 -->setsession sess
272 -->recv quiet
273 -->expecterror 2006,2007
274 -->recvresult
275
276 -->closesession abort
277
278
279 # Can't test via normal means: Close_net_error
280
281 -->title #Close_fatal_error
282
283 -->title -Authentication error
284
285 -->newsession sess -
286 -->callmacro Verify_its_xprotocol_connection
287 Mysqlx.Session.AuthenticateStart {
288 mech_name: "invalid"
289 }
290 -->recverror 1251
291
292 -->closesession abort
293
294 -->title -Authentication error (try to close normally)
295 -->newsession sess -
296 -->callmacro Verify_its_xprotocol_connection
297 Mysqlx.Session.AuthenticateStart {
298 mech_name: "invalid"
299 }
300
301 -->recverror 1251
302
303 -->expecterror 2006,2007
304 -->closesession
305
306 -->title -Disconnect while authenticating
307 -->newsession sess -
308 -->callmacro Verify_its_xprotocol_connection
309 Mysqlx.Session.AuthenticateStart {
310 mech_name: "MYSQL41"
311 }
312
313 -->closesession abort
314
315 -->title -Send unexpected message at handshake
316
317 -->newsession sess -
318 -->callmacro Verify_its_xprotocol_connection
319 Mysqlx.Sql.StmtExecute {
320 stmt: "select 1"
321 }
322
323 -->recverror 5000
324
325 -->closesession abort
326
327 -->title -Disconnect at handshake
328 -->newsession sess -
329 -->callmacro Verify_its_xprotocol_connection
330 -->closesession abort
331
332
333 -->title -Disconnect at handshake
334 -->newsession sess -
335 -->callmacro Verify_its_xprotocol_connection
336 Mysqlx.Connection.CapabilitiesGet {
337 }
338
339 -->closesession abort
340
341
342 -->title #Close_aborted
343
344 -->title -Send illegal message at handshake
345 -->newsession sess -
346 -->callmacro Verify_its_xprotocol_connection
347 -->binsend \x00\xff\xff\xff\xffxxxxx
348
349 -->peerdisc 500 500
350
351 -->title -Send illegal message after handshake
352
353 -->newsession sess x_root
354 -->binsend \x00\xff\xff\xff\xffxxxxx
355
356 -->peerdisc 500 500
357
358 -->title -Connection failure by auth
359
360 -->expecterror 2510
361 -->newsession sess x_root badpass
362
363 ###########
364
365 -->title #Other conditions
366 -->title -Connect and disconnect after queue read timeout
367 -->newsession sess x_root
368
369 # 1s more than the value in the plugin
370 -->varlet %SESSION_MESSAGE_QUEUE_TIMEOUT% 7
371 -->sleep %SESSION_MESSAGE_QUEUE_TIMEOUT%
372
373 -->closesession abort
374
375 -->sleep 1
376
377 #Close_server_shutdown
378 # covered elsewhere
379 ######
380
381 -->title -Final check of clients still around
382
383 -->stmtadmin list_clients
384 -->recvresult
385
386
387 #####
388
389 -->title -Bug #21825183 - WHEN CLIENTS LAST SESSION IS CLOSED THEN NOT ALL QUEUED MESSAGES ARE SEND
390
391 -->newsession sess
392 -->varlet %VALUE% 1234
393 -->repeat 200 %VALUE%
394 Mysqlx.Sql.StmtExecute {
395 stmt:"SELECT %VALUE% as `Column`;"
396 namespace: "sql"
397 }
398 -->endrepeat
399 Mysqlx.Connection.Close {
400 }
401 #-->abort
402 -->repeat 200 %VALUE%
403 -->recvresult
404 -->endrepeat
405 -->recv
406 -->closesession abort
407
408 EOF
409
410
411 --replace_regex /([a-z]*.+localhost[ ]+)[0-9]+/\1$SESSION/
412 --exec $MYSQLXTEST -ux_root --password='' --file=$MYSQL_TMP_DIR/client_close.xpl 2>&1
413
414 # sleep for a while to ensure clean up finished
415 select sleep(10);
416
417 show global status like 'mysqlx_sessions';
418 show global status like 'mysqlx_connections_%';
419 --replace_regex /localhost[:0-9]*/localhost/ /Execute/Query/
420 SELECT `user`,`host`,`db`,`command`,`state`,`info` FROM INFORMATION_SCHEMA.PROCESSLIST WHERE `state` != 'cleaning up' ORDER BY user ASC;
421 drop procedure test.get_stuck;
422
423 ## Cleanup
424 --source ../include/xplugin_cleanup.inc