Bug 1433905 - [mozprocess] Existence of _handle on Windows doesn't mean the process is still alive. draft
authorHenrik Skupin <mail@hskupin.info>
Tue, 29 May 2018 14:48:06 +0200
changeset 801035 46cbb1b664ce35cd90bf43376cfdb33f7d30fd1d
parent 801034 43ead1bad121ad8482e84625ed803323c6ae5650
child 801036 26db3d0158753b139e8e5c0ed3425958bdf7c974
push id111546
push userbmo:hskupin@gmail.com
push dateTue, 29 May 2018 16:17:28 +0000
bugs1433905
milestone62.0a1
Bug 1433905 - [mozprocess] Existence of _handle on Windows doesn't mean the process is still alive. The assumption that when a handle is present for the process handler on Windows doesn't mean that the process is still alive. It could have already been externally killed, crashed, or closed itself. Instead check the process exit code, and run clean-up steps if the process is already gone. MozReview-Commit-ID: 846ZAdsvGmq
testing/mozbase/mozprocess/mozprocess/processhandler.py
--- a/testing/mozbase/mozprocess/mozprocess/processhandler.py
+++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py
@@ -197,24 +197,40 @@ class ProcessHandlerMixin(object):
                     # a signal was explicitly set or not posix
                     send_sig(sig or signal.SIGKILL)
 
             self.returncode = self.wait()
             self._cleanup()
             return self.returncode
 
         def poll(self):
-            """ Popen.poll
-                Check if child process has terminated. Set and return returncode attribute.
+            """Check if child process has terminated, and set returncode attribute.
+
+            This method overrides the Popen.poll implementation for our custom
+            process handling for Windows.
             """
-            # If we have a handle, the process is alive
-            if isWin and getattr(self, '_handle', None):
-                return None
+            if isWin:
+                if self._handle:
+                    returncode = winprocess.GetExitCodeProcess(self._handle)
 
-            return subprocess.Popen.poll(self)
+                    # If the process doesn't exist anymore run cleanup steps
+                    if returncode != winprocess.STILL_ACTIVE:
+                        self.returncode = returncode
+                        self._cleanup()
+                    else:
+                        self.returncode = None
+
+                else:
+                    # Dude, the process is like totally dead!
+                    return self.returncode
+
+            else:
+                self.returncode = subprocess.Popen.poll(self)
+
+            return self.returncode
 
         def wait(self):
             """ Popen.wait
                 Called to wait for a running process to shut down and return
                 its exit code
                 Returns the main process's exit code
             """
             # This call will be different for each OS