[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Ensuring that we're closed when msg() raises SocketClosed
commit fcbbc58d700bb6a22a4d1e7bd7d5fcb22999c9f2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Apr 22 21:14:33 2012 -0700
Ensuring that we're closed when msg() raises SocketClosed
The ControlSocket's recv() method cannot assure that we're closed when it
raises a SocketClosed exception (as explained in 4f8be72), but the
BaseController's msg() method can.
Integ tests were inconsistently failing because I expected to have this
assurance.
---
stem/control.py | 29 +++++++++++++++++++----------
1 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/stem/control.py b/stem/control.py
index 0ed4032..b3bd29c 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -167,16 +167,25 @@ class BaseController:
break
- self._socket.send(message)
- response = self._reply_queue.get()
-
- # If the message we received back had an exception then re-raise it to the
- # caller. Otherwise return the response.
-
- if isinstance(response, stem.socket.ControllerError):
- raise response
- else:
- return response
+ try:
+ self._socket.send(message)
+ response = self._reply_queue.get()
+
+ # If the message we received back had an exception then re-raise it to the
+ # caller. Otherwise return the response.
+
+ if isinstance(response, stem.socket.ControllerError):
+ raise response
+ else:
+ return response
+ except stem.socket.SocketClosed, exc:
+ # If the recv() thread caused the SocketClosed then we could still be
+ # in the process of closing. Calling close() here so that we can
+ # provide an assurance to the caller that when we raise a SocketClosed
+ # exception we are shut down afterward for realz.
+
+ self.close()
+ raise exc
def is_alive(self):
"""
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits