[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Fail gracefully on unexpected close (backport)
Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv5360/lib/mixminion
Modified Files:
Tag: mixminion-v0-0-3-patches
MMTPClient.py test.py
Log Message:
Fail gracefully on unexpected close (backport)
Index: MMTPClient.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/MMTPClient.py,v
retrieving revision 1.24
retrieving revision 1.24.2.1
diff -u -d -r1.24 -r1.24.2.1
--- MMTPClient.py 20 Feb 2003 16:57:39 -0000 1.24
+++ MMTPClient.py 5 May 2003 00:43:30 -0000 1.24.2.1
@@ -67,7 +67,7 @@
errors."""
try:
self._connect(connectTimeout)
- except (socket.error, _ml.TLSError), e:
+ except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
self._raise(e, "connecting")
def _raise(self, err, action):
@@ -78,11 +78,15 @@
tp = "Socket"
elif isinstance(err, _ml.TLSError):
tp = "TLS"
+ elif isinstance(err, _ml.TLSClosed):
+ tp = "TLSClosed"
else:
tp = str(type(err))
- raise MixProtocolError("%s error while %s to %s:%s: %s",
- tp, action, self.targetIP, self.targetPort, err)
-
+ e = MixProtocolError("%s error while %s to %s:%s: %s",
+ tp, action, self.targetIP, self.targetPort, err)
+ e.base = err
+ raise e
+
def _connect(self, connectTimeout=None):
"""Helper method; implements _connect."""
# FFFF There should be a way to specify timeout for communication.
@@ -152,7 +156,7 @@
try:
self.tls.renegotiate()
self.tls.do_handshake()
- except (socket.error, _ml.TLSError), e:
+ except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
self._raise(e, "renegotiating connection")
def sendPacket(self, packet):
@@ -197,7 +201,7 @@
if inp != serverControl+sha1(packet+serverHashExtra):
raise MixProtocolError("Bad ACK received")
LOG.debug("ACK received; packet successfully delivered")
- except (socket.error, _ml.TLSError), e:
+ except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
self._raise(e, "sending packet")
def shutdown(self):
@@ -209,7 +213,7 @@
self.tls.shutdown()
if self.sock is not None:
self.sock.close()
- except (socket.error, _ml.TLSError), e:
+ except (socket.error, _ml.TLSError, _ml.TLSClosed), e:
self._raise(e, "closing connection")
LOG.debug("Connection closed")
Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.94
retrieving revision 1.94.2.1
diff -u -d -r1.94 -r1.94.2.1
--- test.py 20 Feb 2003 16:57:40 -0000 1.94
+++ test.py 5 May 2003 00:43:30 -0000 1.94.2.1
@@ -3156,7 +3156,9 @@
# Was an exception raised?
self.assertEquals(1, len(excList))
# Was it the right exception?
- self.assert_(isinstance(excList[0][1], _ml.TLSClosed))
+ ex = excList[0][1]
+ self.assert_(isinstance(ex, MixError))
+ self.assert_(isinstance(ex.base, _ml.TLSClosed))
for _ in xrange(3):
server.process(0.1)