Bug 1414882 - Require successful handshake in raise_for_port. r=ato
authorHenrik Skupin <mail@hskupin.info>
Wed, 08 Nov 2017 15:30:40 +0100
changeset 444546 b453363d696813572e8305a73e1f2432d7047891
parent 444545 1843a786310a24d555f2cd5083ac94c667685325
child 444547 05f364c80abf777d9ae31665023e3e7582ab9f33
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1414882
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1414882 - Require successful handshake in raise_for_port. r=ato In case another application is still using the port, and the handshake with Marionette server is not successful, the function should return immediately. Otherwise it has to continue to wait until a successful connection has been made.. MozReview-Commit-ID: CuOMNotmCDP
testing/marionette/client/marionette_driver/marionette.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -682,44 +682,31 @@ class Marionette(object):
         runner = None
         if self.instance is not None:
             runner = self.instance.runner
 
         poll_interval = 0.1
         starttime = datetime.datetime.now()
         timeout_time = starttime + datetime.timedelta(seconds=timeout)
 
+        client = transport.TcpTransport(self.host, self.port, 0.5)
+
         connected = False
         while datetime.datetime.now() < timeout_time:
             # If the instance we want to connect to is not running return immediately
             if runner is not None and not runner.is_running():
                 break
 
-            sock = None
             try:
-                sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-                sock.settimeout(0.5)
-                sock.connect((self.host, self.port))
-                data = sock.recv(16)
-
-                # If the application starts up very slowly (eg. Fennec on Android
-                # emulator) a response package has to be received first. Otherwise
-                # start_session will fail (see bug 1410366 comment 32 ff.)
-                if ":" in data:
-                    connected = True
-                    break
+                client.connect()
+                return True
             except socket.error:
                 pass
             finally:
-                if sock is not None:
-                    try:
-                        sock.shutdown(socket.SHUT_RDWR)
-                    except:
-                        pass
-                    sock.close()
+                client.close()
 
             time.sleep(poll_interval)
 
         if not connected:
             raise socket.timeout("Timed out waiting for connection on {0}:{1}!".format(
                 self.host, self.port))
 
     @do_process_check