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
else:
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.start_binary(self.startup_timeout)
self.timeout = Timeouts(self)
@property
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))
+
try:
self.instance.start()
self.raise_for_port(timeout=timeout)
except socket.timeout:
# Something went wrong with starting up Marionette server. Given
# that the process will not quit itself, force a shutdown immediately.
self.cleanup()