[tor-commits] [arm/master] Stem calls lacked an isAlive() check

atagar at torproject.org atagar at torproject.org
Mon Dec 17 04:25:17 UTC 2012


commit edc2447b4b3a2b01ef2b2314edf72478d8f7ac0c
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Dec 16 11:32:12 2012 -0800

    Stem calls lacked an isAlive() check
    
    When arm's controller is detached its 'conn' and 'controller' attributes are
    None. This means that all of our function calls need an isAlive() check before
    using them...
    
    atagar at morrigan:~/Desktop/arm$ ./arm
    Traceback (most recent call last):
      File "./src/starter.py", line 566, in <module>
        _loadConfigurationDescriptions(pathPrefix)
      File "./src/starter.py", line 162, in _loadConfigurationDescriptions
        util.torConfig.loadOptionDescriptions(descriptorPath)
      File "/home/atagar/Desktop/arm/src/util/torConfig.py", line 137, in loadOptionDescriptions
        torVersion = torTools.getConn().getInfo("version", "")
      File "/home/atagar/Desktop/arm/src/util/torTools.py", line 725, in getInfo
        return self.controller.get_info(param, default)
    AttributeError: 'NoneType' object has no attribute 'get_info'
    
    Ideally we'd just drop arm's controller and use stem's (which has its own
    locks and check for this), but that'll need to come later.
---
 src/util/torTools.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index 92d2cf0..79b4e70 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -721,6 +721,12 @@ class Controller(TorCtl.PostEventListener):
     self.connLock.acquire()
     
     try:
+      if not self.isAlive():
+        if default != UNDEFINED:
+          return default
+        else:
+          raise stem.SocketClosed()
+      
       if default != UNDEFINED:
         return self.controller.get_info(param, default)
       else:
@@ -748,6 +754,12 @@ class Controller(TorCtl.PostEventListener):
     self.connLock.acquire()
     
     try:
+      if not self.isAlive():
+        if default != UNDEFINED:
+          return default
+        else:
+          raise stem.SocketClosed()
+      
       if default != UNDEFINED:
         return self.controller.get_conf(param, default, multiple)
       else:
@@ -790,6 +802,9 @@ class Controller(TorCtl.PostEventListener):
     self.connLock.acquire()
     
     try:
+      if not self.isAlive():
+        raise stem.SocketClosed()
+      
       # clears our exit policy chache if it's changing
       if "exitpolicy" in [k.lower() for (k, v) in paramList]:
         self._exitPolicyChecker = self.getExitPolicy()





More information about the tor-commits mailing list