1# In embedded server we don't really have a control over stack usage 2-- source include/not_embedded.inc 3 4# 5# Bug#21476: Lost Database Connection During Query 6# 7# When the amount of stack space we think we need to report an error is 8# actually too small, then we can get SEGVs. But, we don't want to reserve 9# space that we could use to get real work done. So, we want the reserved 10# space small, and this test verifies that the reservation is not too small. 11 12CREATE TABLE `t_bug21476` ( 13 `ID_BOARD` smallint(5) unsigned NOT NULL default '0', 14 `ID_MEMBER` mediumint(8) unsigned NOT NULL default '0', 15 `logTime` int(10) unsigned NOT NULL default '0', 16 `ID_MSG` mediumint(8) unsigned NOT NULL default '0', 17 PRIMARY KEY (`ID_MEMBER`,`ID_BOARD`), 18 KEY `logTime` (`logTime`) 19) ENGINE=MyISAM DEFAULT CHARSET=cp1251 COLLATE=cp1251_bulgarian_ci; 20 21INSERT INTO `t_bug21476` VALUES (2,2,1154870939,0),(1,2,1154870957,0),(2,183,1154941362,0),(2,84,1154904301,0),(1,84,1154905867,0),(2,13,1154947484,10271),(3,84,1154880549,0),(1,6,1154892183,0),(2,25,1154947581,10271),(3,25,1154904760,0),(1,25,1154947373,10271),(1,179,1154899992,0),(2,179,1154899410,0),(5,25,1154901666,0),(2,329,1154902026,0),(3,329,1154902040,0),(1,329,1154902058,0),(1,13,1154930841,0),(3,85,1154904987,0),(1,183,1154929665,0),(3,13,1154931268,0),(1,85,1154936888,0),(1,169,1154937959,0),(2,169,1154941717,0),(3,183,1154939810,0),(3,169,1154941734,0); 22 23delimiter //; 24let $query_head=UPDATE t_bug21476 SET ID_MSG = IF(logTime BETWEEN 1 AND 1101770053, 2, // 25let $query_tail =) WHERE logTime BETWEEN 1 AND 1104091539 AND ID_MSG = 0// 26 27# Scan over the possible stack heights, trying to recurse to exactly that 28# depth. Eventually, we will reach our imposed limit on height and try to 29# raise an error. If the remaining stack space is enough to raise that error, 30# we will get an error-number of 1436 and quit the loop. If it's not enough 31# space, we should get a SEGV 32 33# Well more than enough recursions to find the end of our stack. 34let $i = 100000// 35disable_query_log// 36disable_result_log// 37while ($i) 38{ 39 # If we SEGV because the min stack size is exceeded, this would return error 40 # 2013 . 41 error 0,ER_STACK_OVERRUN_NEED_MORE // 42 eval $query_head 0 $query_tail// 43 44 if ($mysql_errno) 45 { 46 # We reached the place where we reported an error about the stack limit, 47 # and we successfully returned the error. That means that at the stack 48 # limit, we still have enough space reserved to report an error. 49 let $i = 1// 50 51 # Check that mysql_errname is ER_STACK_OVERRUN_NEED_MORE 52 if ($mysql_errname != ER_STACK_OVERRUN_NEED_MORE) 53 { 54 die Wrong error triggered, expected ER_STACK_OVERRUN_NEED_MORE but got $mysql_errname// 55 } 56 57 } 58 59 # Multiplying by three stack frames should be fine enough resolution. 60 # Trading exactness for speed. 61 62 # go one more level deep 63 let $query_head = $query_head IF(logTime <= 1104091$i, $i, // 64 let $query_tail =) $query_tail// 65 66 # go one more level deep 67 let $query_head = $query_head IF(logTime <= 1105091$i, $i, // 68 let $query_tail =) $query_tail// 69 70 # go one more level deep 71 let $query_head = $query_head IF(logTime <= 1106091$i, $i, // 72 let $query_tail =) $query_tail// 73 74 dec $i// 75} 76enable_result_log// 77enable_query_log// 78 79echo Assertion: mysql_errname ER_STACK_OVERRUN_NEED_MORE == $mysql_errname// 80 81delimiter ;// 82DROP TABLE `t_bug21476`; 83 84--echo End of 5.0 tests. 85