Bug 1413852 - TcpTransport.receive() doesn't obey current socket timeout. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 02 Nov 2017 11:33:23 +0100
changeset 692030 6daafc8145adb77c5a786dc8bd0e7060fc66f374
parent 687186 aa958b29c149a67fce772f8473e9586e71fbdb46
child 692042 1cc6c5c81678b3a5aae347ceca803bedd1653a7e
child 692043 bd3cd88269d0da7b27bbf324dbb93c255879b9c4
push id87367
push userbmo:hskupin@gmail.com
push dateThu, 02 Nov 2017 10:37:36 +0000
bugs1413852
milestone58.0a1
Bug 1413852 - TcpTransport.receive() doesn't obey current socket timeout. The getter for socket_timeout should always return the current socket timeout from the socket instance first, and only fallback to the private property if no socket instance exists. This ensures that all methods will always operate on the current socket timeout value. Also using a timeout of 2s for receiving the hello string might be too less for slow running builds. To prevent intermittent failures for start_session, a good value might be 60s. MozReview-Commit-ID: HywjFfClrRr
testing/marionette/client/marionette_driver/transport.py
--- a/testing/marionette/client/marionette_driver/transport.py
+++ b/testing/marionette/client/marionette_driver/transport.py
@@ -104,23 +104,27 @@ class TcpTransport(object):
         self.protocol = self.min_protocol_level
         self.application_type = None
         self.last_id = 0
         self.expected_response = None
         self.sock = None
 
     @property
     def socket_timeout(self):
+        if self.sock:
+            return self.sock.gettimeout()
+
         return self._socket_timeout
 
     @socket_timeout.setter
     def socket_timeout(self, value):
+        self._socket_timeout = value
+
         if self.sock:
             self.sock.settimeout(value)
-        self._socket_timeout = value
 
     def _unmarshal(self, packet):
         msg = None
 
         # protocol 3 and above
         if self.protocol >= 3:
             typ = int(packet[1])
             if typ == Command.TYPE:
@@ -187,17 +191,17 @@ class TcpTransport(object):
 
             self.sock.connect((self.addr, self.port))
         except:
             # Unset self.sock so that the next attempt to send will cause
             # another connection attempt.
             self.sock = None
             raise
 
-        with SocketTimeout(self.sock, 2.0):
+        with SocketTimeout(self.sock, 60.0):
             # first packet is always a JSON Object
             # which we can use to tell which protocol level we are at
             raw = self.receive(unmarshal=False)
         hello = json.loads(raw)
         self.protocol = hello.get("marionetteProtocol", self.min_protocol_level)
         self.application_type = hello.get("applicationType")
 
         return (self.protocol, self.application_type)