summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2021-09-24 01:33:05 +0200
committerVladislav Vaintroub <wlad@mariadb.com>2021-09-24 11:49:28 +0200
commitca7046dc19d8bbb5916c89d9e98e9d4632294fa8 (patch)
tree1dd01cce606bc79e2516519b4e47ea5855288e0d /client
parent4bfdba2e89ce825a9f89b2e6ed7eca3e0ce2c128 (diff)
downloadmariadb-git-ca7046dc19d8bbb5916c89d9e98e9d4632294fa8.tar.gz
MDEV-11499 mysqltest, Windows : improve diagnostics if server fails to shutdown
Create minidump when server fails to shutdown. If process is being debugged, cause a debug break. Moves some code which is part of safe_kill into mysys, as both safe_kill, and mysqltest produce minidumps on different timeouts. Small cleanup in wait_until_dead() - replace inefficient loop with a single wait.
Diffstat (limited to 'client')
-rw-r--r--client/mysqltest.cc54
1 files changed, 47 insertions, 7 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index ad1eb29ab70..82bd1abf1a3 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -5026,13 +5026,34 @@ int query_get_string(MYSQL* mysql, const char* query,
}
+#ifdef _WIN32
+#define SIGKILL 9
+#include <my_minidump.h>
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)
+ if (sig == SIGABRT)
+ {
+ /*
+ Create a minidump. If process is being debugged, debug break
+ Otherwise, terminate.
+ */
+ verbose_msg("Aborting %d",pid);
+ my_create_minidump(pid,TRUE);
+ proc= OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
+ if(!proc)
+ return -1;
+ BOOL debugger_present;
+ if (CheckRemoteDebuggerPresent(proc,&debugger_present) && debugger_present)
+ {
+ if (DebugBreakProcess(proc))
+ {
+ CloseHandle(proc);
+ return 0;
+ }
+ }
+ }
+ else if ((proc= OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid)) == NULL)
return -1;
if (sig == 0)
{
@@ -5043,12 +5064,30 @@ static int my_kill(int pid, int sig)
(void)TerminateProcess(proc, 201);
CloseHandle(proc);
return 1;
-#else
- return kill(pid, sig);
-#endif
}
+/* Wait until process is gone, with timeout */
+static int wait_until_dead(int pid, int timeout)
+{
+ HANDLE proc= OpenProcess(SYNCHRONIZE, FALSE, pid);
+ if (!proc)
+ return 0; /* already dead */
+ DBUG_ASSERT(timeout >= 0);
+ DBUG_ASSERT(timeout <= UINT_MAX/1000);
+ DWORD wait_result= WaitForSingleObject(proc, (DWORD)timeout*1000);
+ CloseHandle(proc);
+ return (int)wait_result;
+}
+
+#else /* !_WIN32 */
+
+
+static int my_kill(int pid, int sig)
+{
+ DBUG_PRINT("info", ("Killing server, pid: %d", pid));
+ return kill(pid, sig);
+}
/*
Shutdown the server of current connection and
@@ -5083,6 +5122,7 @@ static int wait_until_dead(int pid, int timeout)
}
DBUG_RETURN(1); // Did not die
}
+#endif /* _WIN32 */
void do_shutdown_server(struct st_command *command)