Bug 1223277 - TcpTransport.close() should't care about errno 107. draft
authorHenrik Skupin <mail@hskupin.info>
Thu, 22 Jun 2017 21:10:44 +0200
changeset 600720 6d9efd8a7491ad6d8bfd5a5ab31315cc9d60dc70
parent 600719 f35b9ea06142abbd183a82e59f6121055adf5dd3
child 600721 6985541f8aaa2dd2e76162c6567c88aa9d56bbb9
push id65860
push userbmo:hskupin@gmail.com
push dateTue, 27 Jun 2017 20:00:08 +0000
bugs1223277
milestone56.0a1
Bug 1223277 - TcpTransport.close() should't care about errno 107. Beside Errno 57 there is also Errno 107 (Transport endpoint is not connected) which can happen in case of an unexpected crash/shutdown of Firefox. Then calling shutdown() on the socket to stop the communication will fail. This is most likely a race and can happen after receiving a reply from the server, and before sending another command. MozReview-Commit-ID: 3S5Ko4XVUAJ
testing/marionette/client/marionette_driver/transport.py
--- a/testing/marionette/client/marionette_driver/transport.py
+++ b/testing/marionette/client/marionette_driver/transport.py
@@ -279,22 +279,30 @@ class TcpTransport(object):
         to come back.
         """
         self.last_id = self.last_id + 1
         cmd = Command(self.last_id, name, params)
         self.send(cmd)
         return self.receive()
 
     def close(self):
-        """Close the socket."""
+        """Close the socket.
+
+        First forces the socket to not send data anymore, and then explicitly
+        close it to free up its resources.
+
+        See: https://docs.python.org/2/howto/sockets.html#disconnecting
+        """
         if self.sock:
             try:
                 self.sock.shutdown(socket.SHUT_RDWR)
             except IOError as exc:
-                # Errno 57 is "socket not connected", which we don't care about here.
-                if exc.errno != 57:
+                # If the socket is already closed, don't care about:
+                #   Errno  57: Socket not connected
+                #   Errno 107: Transport endpoint is not connected
+                if exc.errno not in (57, 107):
                     raise
 
             self.sock.close()
             self.sock = None
 
     def __del__(self):
         self.close()