Bug 1410366 - Improve socket handling in wait_for_port
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
--- 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.