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
--- 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()