Skip to content

Commit

Permalink
Have mysqltest first send SIGABRT, then SIGKILL
Browse files Browse the repository at this point in the history
This is to get core's in mysql-test-run if server doesn't die in shutdown
  • Loading branch information
montywi authored and vuvova committed Aug 23, 2017
1 parent 25c06f5 commit e208100
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
55 changes: 42 additions & 13 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5102,7 +5102,9 @@ int query_get_string(MYSQL* mysql, const char* query,

static int my_kill(int pid, int sig)
{
DBUG_PRINT("info", ("Killing server, pid: %d", pid));
#ifdef _WIN32
#define SIGKILL 9 /* ignored anyway, see below */
HANDLE proc;
if ((proc= OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid)) == NULL)
return -1;
Expand Down Expand Up @@ -5137,6 +5139,26 @@ static int my_kill(int pid, int sig)
*/


static int wait_until_dead(int pid, int timeout)
{
DBUG_ENTER("wait_until_dead");
/* Check that server dies */
while (timeout--)
{
if (my_kill(pid, 0) < 0)
{
DBUG_PRINT("info", ("Process %d does not exist anymore", pid));
DBUG_RETURN(0);
}
DBUG_PRINT("info", ("Sleeping, timeout: %d", timeout));
/* Sleep one second */
my_sleep(1000000L);
}
DBUG_RETURN(1); // Did not die
}


void do_shutdown_server(struct st_command *command)
{
long timeout= opt_wait_for_pos_timeout ? opt_wait_for_pos_timeout / 5 : 300;
Expand Down Expand Up @@ -5188,24 +5210,31 @@ void do_shutdown_server(struct st_command *command)
}
DBUG_PRINT("info", ("Got pid %d", pid));

/* Tell server to shutdown if timeout > 0*/
/*
If timeout == 0, it means we should kill the server hard, without
any shutdown or core (SIGKILL)
If timeout is given, then we do things in the following order:
- mysql_shutdown()
- If server is not dead within timeout
- kill SIGABRT (to get a core)
- If server is not dead within new timeout
- kill SIGKILL
*/

if (timeout && mysql_shutdown(mysql, SHUTDOWN_DEFAULT))
die("mysql_shutdown failed");

/* Check that server dies */
while(timeout--){
if (my_kill(pid, 0) < 0){
DBUG_PRINT("info", ("Process %d does not exist anymore", pid));
DBUG_VOID_RETURN;
if (!timeout || wait_until_dead(pid, timeout))
{
if (timeout)
(void) my_kill(pid, SIGABRT);
/* Give server a few seconds to die in all cases */
if (!timeout || wait_until_dead(pid, timeout < 5 ? 5 : timeout))
{
(void) my_kill(pid, SIGKILL);
}
DBUG_PRINT("info", ("Sleeping, timeout: %ld", timeout));
my_sleep(1000000L);
}

/* Kill the server */
DBUG_PRINT("info", ("Killing server, pid: %d", pid));
(void)my_kill(pid, 9);

DBUG_VOID_RETURN;
}

Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb_zip/t/bug56680.test
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ INSERT INTO bug56680_2 VALUES(1,_latin1 0xdf,1);
SELECT HEX(b) FROM bug56680_2 LIMIT 3;
CHECK TABLE bug56680_2;

--let $shutdown_timeout=1
--let $shutdown_timeout=0
--source include/restart_mysqld.inc

CHECK TABLE bug56680_2;
Expand Down

0 comments on commit e208100

Please sign in to comment.