Bug 1410366 - Improve socket handling in wait_for_port r=ato
authorHenrik Skupin <mail@hskupin.info>
Fri, 20 Oct 2017 14:54:03 +0200
changeset 387954 11e5f7b5376f4b8bcb7995330e2a10d0276ccafd
parent 387953 30e69377c285c4f37a35234a5948105199f7913b
child 387955 5129a4cc02b95dd53f295027e000823a1f6050c5
push id32739
push useracraciun@mozilla.com
push dateWed, 25 Oct 2017 09:29:21 +0000
treeherdermozilla-central@252a8528c5ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs1410366
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 1410366 - Improve socket handling in wait_for_port r=ato The temporarily created sockets have to be removed immediately by the operating system. Otherwise those enter the TIME_WAIT state, and will be removed about 90s later. This can cause a pile of orphaned sockets. MozReview-Commit-ID: BGy9ZOjhjT0
testing/marionette/client/marionette_driver/marionette.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -693,22 +693,30 @@ class Marionette(object):
                 return False
 
             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:
                     return True
             except socket.error:
                 pass
             finally:
                 if sock is not None:
+                    try:
+                        sock.shutdown(socket.SHUT_RDWR)
+                    except:
+                        pass
                     sock.close()
 
             time.sleep(poll_interval)
 
         return False
 
     def raise_for_port(self, timeout=None):
         """Raise socket.timeout if no connection can be established.