MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:September 29 2009 10:19pm
Subject:bzr commit into mysql-5.1-mtr branch (vvaintroub:2837) Bug#47731
View as plain text  
#At file:///H:/bzr/51mtr/ based on revid:bjorn.munch@stripped

 2837 Vladislav Vaintroub	2009-09-30
      Bug #47731 mtr freezes for many seconds when process to be killed has already gone. 
      
      The problem is that safe_kill_win fails to detect a dead process. OpenProcess() will 
      succeed even after the process died, it will first fail after the last handle to process 
      is closed.
      
      To fix the problem, check process status with GetExitCodeProcess() and consider 
      process to be dead if the exit code returned by this routine is not STILL_ALIVE.

    modified:
      mysql-test/lib/My/SafeProcess/safe_kill_win.cc
=== modified file 'mysql-test/lib/My/SafeProcess/safe_kill_win.cc'
--- a/mysql-test/lib/My/SafeProcess/safe_kill_win.cc	2008-10-08 20:02:32 +0000
+++ b/mysql-test/lib/My/SafeProcess/safe_kill_win.cc	2009-09-29 22:19:00 +0000
@@ -30,7 +30,7 @@ int main(int argc, const char** argv )
   DWORD pid= -1;
   HANDLE shutdown_event;
   char safe_process_name[32]= {0};
-  int retry_open_event= 100;
+  int retry_open_event= 2;
   /* Ignore any signals */
   signal(SIGINT,   SIG_IGN);
   signal(SIGBREAK, SIG_IGN);
@@ -51,15 +51,31 @@ int main(int argc, const char** argv )
   {
      /*
       Check if the process is alive, otherwise there is really
-      no idea to retry the open of the event
+      no sense to retry the open of the event
      */
     HANDLE process;
-    if ((process= OpenProcess(SYNCHRONIZE, FALSE, pid)) == NULL)
+    DWORD exit_code;
+    process= OpenProcess(SYNCHRONIZE| PROCESS_QUERY_INFORMATION, FALSE, pid);
+    if (!process)
     {
-      fprintf(stderr, "Could not open event or process %d, error: %d\n",
-            pid, GetLastError());
-      exit(3);
+      /* Already died */
+      exit(1);
+    }
+
+    if (!GetExitCodeProcess(process,&exit_code))
+    {
+       fprintf(stderr,  "GetExitCodeProcess failed, pid= %d, err= %d\n",
+         pid, GetLastError());
+       exit(1);
     }
+
+    if (exit_code != STILL_ACTIVE)
+    {
+       /* Already died */
+       CloseHandle(process);
+       exit(2);
+    }
+
     CloseHandle(process);
 
     if (retry_open_event--)


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20090929221900-95w2p5qtkegi6s6p.bundle
Thread
bzr commit into mysql-5.1-mtr branch (vvaintroub:2837) Bug#47731Vladislav Vaintroub30 Sep