Bug 1240601 - Set timeout on socket in transport.wait_for_port; r=automatedtester
authorAndreas Tolfsen <ato@mozilla.com>
Mon, 18 Jan 2016 22:12:55 +0000
changeset 281946 5c139df9284476d17b5d4f4019ba1fbf12504c07
parent 281945 cdd0f1f00cda3459b43581e1e7747eec87079be9
child 281947 77937735dd001453e388387f1ecacc20317540cd
push id29950
push usercbook@mozilla.com
push dateThu, 28 Jan 2016 11:14:03 +0000
treeherdermozilla-central@2b73b0a4d52b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersautomatedtester
bugs1240601
milestone47.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 1240601 - Set timeout on socket in transport.wait_for_port; r=automatedtester If the client is able to connect but the server never sends any data, the socket should time out in order for the function not to hang forever. That said, polling for ports like this is inherently racy and we should instead specify and bind what port we wish Marionette to start on in the future.
testing/marionette/transport/marionette_transport/transport.py
--- a/testing/marionette/transport/marionette_transport/transport.py
+++ b/testing/marionette/transport/marionette_transport/transport.py
@@ -284,27 +284,28 @@ class TcpTransport(object):
             self.sock.close()
 
     def __del__(self):
         self.close()
         self.sock = None
 
 
 def wait_for_port(host, port, timeout=60):
-    """ Wait for the specified host/port to be available."""
+    """Wait for the specified host/port to become available."""
     starttime = datetime.datetime.now()
     poll_interval = 0.1
     while datetime.datetime.now() - starttime < datetime.timedelta(seconds=timeout):
         sock = None
         try:
             sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            sock.settimeout(0.5)
             sock.connect((host, port))
             data = sock.recv(16)
             sock.close()
-            if ':' in data:
+            if ":" in data:
                 return True
         except socket.error:
             pass
         finally:
-            if sock:
+            if sock is not None:
                 sock.close()
         time.sleep(poll_interval)
     return False