Bug 1449862 - [marionette] Check for available port each time before starting binary. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 29 Mar 2018 10:01:45 +0200
changeset 774629 dff2f57fa52c113b8492824c97aecf563517f7b1
parent 774627 1b653c3d140dc9ffac791271930b8d2ad8d29405
push id104456
push userbmo:hskupin@gmail.com
push dateThu, 29 Mar 2018 08:07:17 +0000
Bug 1449862 - [marionette] Check for available port each time before starting binary. To prevent race conditions when a formerly started Firefox instance is still claiming the port of the server socket, the port availability has to be checked each time before the binary gets started. Otherwise the client could accidentally connect to the wrong process, and also would run the remaining tests with it. MozReview-Commit-ID: JUaHYD2b1Rf
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -610,32 +610,31 @@ class Marionette(object):
             self.socket_timeout = float(socket_timeout)
         if startup_timeout is None:
             self.startup_timeout = self.DEFAULT_STARTUP_TIMEOUT
             self.startup_timeout = int(startup_timeout)
         if self.bin:
-            if not Marionette.is_port_available(self.port, host=self.host):
-                ex_msg = "{0}:{1} is unavailable.".format(self.host, self.port)
-                raise errors.MarionetteException(message=ex_msg)
             self.instance = GeckoInstance.create(
                 app, host=self.host, port=self.port, bin=self.bin, **instance_args)
         self.timeout = Timeouts(self)
     def profile_path(self):
         if self.instance and self.instance.profile:
             return self.instance.profile.profile
     def start_binary(self, timeout):
+        if not self.is_port_available(self.port, host=self.host):
+            raise IOError("Port {0}:{1} is unavailable.".format(self.host, self.port))
         except socket.timeout:
             # Something went wrong with starting up Marionette server. Given
             # that the process will not quit itself, force a shutdown immediately.